Node Package Manager | Node.Js Tutorial #3

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

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)?

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!

Tanmay Sinha

Author

  • Tanmay Sinha

    Founder & CEO of MrProgrammer.in | I help Learning Freaks to Step into the World of Programming and Our Mission is to Provide High Quality and Valuable Content to Our Users! We believe that everyone has the potential to learn to code, and we are committed to making that happen. Our courses are designed to be engaging and interactive, and we offer a variety of learning paths to meet the needs of all learners. We are also committed to providing our learners with the support they need to succeed, and we offer a variety of resources to help learners learn at their own pace. If you are interested in learning to code, we encourage you to check out our courses. We are confident that you will find our content to be high-quality, valuable, and makes sense.

Leave a Reply