node.js and npm
1. Input and output operations in Node.js are done in an asynchronous manner. Explain what this means and also discuss why this is an advantageous design for a web server to use.
2. Outline the request methods and URL combinations for storing information about users of the system (e.g. POST /someURL, GET /someURL) that your server could use to allow a client to: create a new user on the system, access the list of users, and access a specific user on the server. For POST requests, outline what the data expectations of the request are.
3.Describe what you think the advantage(s) of using a package manager such as NPM for a project will be? (a project is planned to work on with several people over the next five years. )
Ans-1) As stated Node.js is a Javascript runtime and it is asynchronous in nature. It means that the code executes without depending on the execution of the previous lines. When the Javascript engine runs the code, it converts it into the Promise type and then executes it asynchronously.Node.js operates on a single-thread, using non-blocking I/O calls, allowing it to support tens of thousands of concurrent connections held in the event loop.
The advantage is that the program doesn’t have to wait for the execution of the further code while the previous code is currently being executed. Hence, increasing the efficiency and throughput of the program. It also helps in faster execution of programs.
Ans-2 )
var request = require('request');
request.post(
'http://www.mysite.com/page',
{ json: { key: 'value' } },
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
Ans-3)As our project will be for next 5 years and multiple people will be involved then it will be advantageous using NPM as its job is to present an interface that assists the user in managing the collection of packages installed on their system.In our case all the people will work on their own module and in such big projects it may become hectic and inefficient and also result in redundancy.So to avoid this it will be beneficial to use NPM
Get Answers For Free
Most questions answered within 1 hours.