What is Node js?
What is NPM?
Installing Node and NPM
Node is highly cross-platform and is available for many operating systems. The source code is open source and binaries are available for Windows, Mac, Linux, and Sun operating system. Additionally, a docker image is also distributed for use with docker container apps.
There are 2 major versions of Node currently available.
- Node v8.12 with NPM v6.4.1 is the current stable and LTS release of node.
- Node v10.10 with NPM v6.4.1 is the latest Non-LTS release.
As a beginner, It is suggested that you use the LTS release since a lot of packages are built specifically for LTS releases. The newer releases have experimental features that are not yet stable. Installation for Windows and Mac is pretty simple. You just need to download the binaries from this page and keep following the instructions.
For Linux and other systems where package managers like apt, yum etc are used, installation instructions are available here.
Whenever you work on a Node project, it is suggested that you initialize it. Initializing a Node project is fairly easy. CD into your project folder and run npm init. You will be asked a few questions about the project like its name, description, author etc.
Congratulations, you have just initialized an npm project. You will now have a package.json file in your project directory with a similar structure. This is JSON representation of your project details.
"test": "echo \"Error: no test specified\" && exit 1"
"author": "Rishabh Kandari",
Now it is time to install some libraries made by other people. To do this, we will be using the npm install command. Let’s install the momentjs library by running the following command.
npm install moment
Now, before we go ahead, I want you to peep into your project folder. It should have the following structure by now.
You have a new package.lock.json file and a folder called node_modules. This folder houses all the libraries you have installed for this project. To uninstall the same library you can run
npm uninstall moment. To list all dependencies of your project, run
npm list. A full list of available commands can be viewed on running