Skip to content

ADVERTISEMENT

Home » Blogs » What is Node Package Manager? | Node.Js Tutorial #3

What is Node Package Manager? | Node.Js Tutorial #32 min read

Node Package Manager | Node.Js Tutorial #3

Hey Programmers, In the Prevoius Two Parts We Learned About NodeJS, From Writing Our First Hello World Program to Working With Modules And Creating a Basic Web Server Project Using NodeJS. If you Missed the Prevoius Posts You can Access Them Here: Node.Js Tutorial #1 & Node.Js Tutorial #2. In This Post We Will Be Learning About NPM Which is Node Package Manager.

What is Node Package Manager (NPM)?

ADVERTISEMENT

NPM is a Package Manger For NodeJS, Or In Other Words It is a Hub of Multiple Modules & Packages Used for Devvelopment. NodeJS Has a It’s Website https://www.npmjs.com/ which Manages Thousands Of Packages Of NodeJS. NPM is Built-In With NodeJS there is No Need To Install NPM Seperately.

What are Packages In NodeJS?

Packages Contains the Files Required For a Module Used For Development. Modules are Like JavaScript Libraries Which can Be Later On Imported To any Project.

How to Download a Package Using NodeJS?

Downloading Package Using NPM is Not a Big Task, It Is Very Easy And Simple to Install, In Order to Install a Module Using NPM Follow the Steps:

Step 1: Open CMD or Terminal (for linux users) And Use the Keyword NPM Before the Name of the Package. For Example: npm install express

npm install express
image 2

Step 3: Hit the ‘Enter’ Button on the Keyboard And Your Package Will Start Installing all the Files Required For the Module.

Step 4: Congrats! You Have Installed Your First NPM Package

By Installing a Module Using NPM It Will Create a New Folder called ‘node modules‘ Where all the Packages are Installed.

Using a Package In NodeJS?

After you Have Installed the Package, We Have to Also Use the Installed Package. Follow the Steps to Import a Package In a Program: For Example using HTTP Module Package

var http = require('mysql')
var mysql = require('mysql')

var con =  mysql.createConnection({
    host: "localhost",
    user: "root",
    password: ""
});

con.connect(function(err){
    if(err) throw err;
    console.log("Connected! With Database");
}); 

So this Was it For this Blog, See You In the Next One Till Then Keep Coding Keep Exploring!

ADVERTISEMENT

Leave a Reply