How to Install a Module/Package/Library in NodeJs

Posted on September 6, 2019 at 9:59 am

Do you need to install a NodeJs module/package/library?

First create the project directory:

mkdir TestProject
cd TestProject

Make the directory the root of your project:

npm init --yes

Install the required NodeJs modules/packages (i.e “request”):

npm install request --save

* With -save parameter, the installed modules will be saved as project dependency!

Now create a file “test.js” with this content:

var request = require('request');
 
request.get('https://www.google.com/', function(error, response, body) 
{
    if (!error && response.statusCode == 200) console.log(body);
});

And finally run your script with:

node test.js

Receive updates via email

Other Posts

Updated Posts