Node

An open-source JavaScript server framework

Top 7 fastest server-side languages

Use JavaScript on frontend and backend

Node

NPM

A module and package manager for Node

NPM

Basic Commands

Create a Node Project

You can create a parent directory and root


mkdir -p folder/subfolder


or you can create just the root


mkdir folder


Then create a package.json (follow the instructions)


npm init


Add a Node Module to package.json

Find a module on NPM

Then add to package.json

(where NODE_MODULE is your selected module)


npm install NODE_MODULE --save


Clean Out Node Modules

Delete the local module repository

Clean out the cache


rm -rf node_modules
npm cache clean


Install the Dependencies

Use this to install the dependencies per package.json


npm install


Install only the production dependencies (no dev)


npm install --production


Remove Unneeded Local Modules

Wipe out unused local modules


npm prune


Start the Node Server

Look in your package.json

Find the field main - you should find the main server script

(where SERVER_SCRIPT is your main script - usually index.js)


node SERVER_SCRIPT

Or look at scripts and execute the relevant script

(where SERVER_SCRIPT is your selected script - usually start)


npm SERVER_SCRIPT