AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

Node.js NPM Modules


<< Previous Page
Nodejs tutorial
Next Page >>
Nodejs tutorial

Node.js Tutorial » Node.js NPM Modules

What is NPM Modules?

NPM is a package manager for the Node.js packages or modules you want.

You can find hundreds of free packages on www.npmjs.com to download and use for what you need.

When you install node js the NPM packages are already on your computer.

 

What is a Package NPM?

An NPM package in Node.js contains all the files when you need a module.

Modules are JavaScript libraries that you can include in your project.

Installing Modules using NPM

Simple syntax to install any module Node.js

$ npm install <Module_Name>

For example, following is the command to install a famous Node.js web framework module called express

$ npm install express

Now you can use this module in your js file as following −

var express = require('express');

Related subjects:
node.js http module node.js modules global objects nodejs

 

Tags: nodejs npm install, version table, start, package, init, build, run build, tutorial, Node Package Manager
What is npm and Nodejs?
Does npm come with Nodejs?
How install Node JS npm Linux?

 

Download a Package

Downloading a package is very easy way.

To make the download possible open the command line interface choose the desired package and tell NPM to download.

As an example, download a package called "upper-case":

Download "upper-case":
E:\Users\node_js_pack>npm install upper-case

In this way you have downloaded and installed the first package called "upper-case"!

NPM itself creates a folder named "node_modules", where the package will be placed. All packages you install in the future will be placed in this "node_modules" folder.

Your project now has a folder structure like this:

E:\Users\My_Name\node_modules\upper-case

 

How to use a Package

Once the package has been installed, it is ready to use.

Let's use the "upper-case" package once downloaded, and the other modules can be installed in the same way and inserted in the same directory.

Example:
var uc = require('upper-case');

Let's create a Node.js file that will convert the result "Hi, this is a script" into upper-case letters.

Example:
var http = require('http');
var uc = require('upper-case');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(uc.upperCase("Hi, this is a script"));
res.end();
}).listen(8888);

We save the above code to a file named "demo_test_upper-case.js" and start the file:

Initiate demo_test_upper-case.js:
E:\Users\My_Name>node demo_test_upper-case.js

 



nodejs npm install, version table, start, package, init, build, run build, tutorial, Node Package Manager
What is npm and Nodejs?
Does npm come with Nodejs?
How install Node JS npm Linux?
Node.js NPM Modules - nodejs

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


CSS background color - opacity, gradient...
CSS flex - display: flex - CSS Flexbox L...
CSS border padding...
HTML text center horizontally and vertic...
HTML text input <input type="text"&g...
HTML link color...
How to Link CSS to HTML, external file n...
HTML link - hyperlink...
jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...