Node js is an open-source cross-platform real-time environment for the development of server-side web applications. It is also capable of asynchronous IO due to the presence of event-driven architecture. It uses an event-driven non-blocking IO model that makes it very easy to handle and efficient. In this article, we will discuss the basics of initiation of development with node.js.

Get started with node js and NPM

To get started with node js along with npm, very easy with the help of the installer package that can found at a node js official website.

  • Download and get started with node js from the website.
  • Run the installer on your computer.
  • You will need to follow the following steps and agree with the license agreement with the help of a box provided next to the button.
  • Restart your computer system.
  • Now you will need to test node.js by printing a version with the help of the following command in the command section –
  • node -v

This will help you interesting NPM by printing its version with the help of command –

npm -v

A very simple way to test and get started with node js working in your system to create a JavaScript file that can print a message. Here is how you can create a test.js file in node.

/*test.js file*/
console.log("Node is working");

Now you will need to run this test.js file with the help of the node command and node test.js in the command prompt.

This is the complete process of installation of node.js and NPM.

get started with node js

Node Package Module

NPM is a kind of package module that can help JavaScript developers load dependencies lesser and more effective coding. To do this we will just have to run a command in the command prompt –

 npm install

This command will help you in finding a JSON file named package.json. this will be present in the root directory to install all dependencies defined in the file package.

Package.json usually looks like this –

{
"name": "ApplicationName",
 "version": "0.0.1",
"description": "Application Description",
"main": "server.js",
"scripts": {
"start": "node server.js"
 },
"repository": {
"type": "git",
"url": "https://github.com/npm/npm.git"
},
"dependencies": {
"express": "~3.0.1",
"sequelize": "latest",
"q": "latest",
"tedious": "latest",
"angular": "latest",
"angular-ui-router": "~0.2.11",
"path": "latest",
"dat-gui": "latest"
}
}

The most crucial thing in your package.json is the name and the version. The name in the version needed and your package can’t install without the help of these. The name and the version of the package file create an identifier assumed as very unique. Changes to the package come with the changes in the version of the package.

Repository

{
"repository": {
"type": "git",
"url": "https://github.com/npm/npm.git"
}
}

You will need to specify the places where the code you are writing will be staying. With the help of the repository, developers can easily reach out and contribute to your application. If the GIT repository is not GitHub even then the npm command is effective enough to find you easily.

Scripts

{
"scripts": {
"start": "node server.js"
}
}

NPM and node.js provide us with several very useful scripts such as npm install npm start npm stop.

Some default script values are completely dependent on the contents of the package –

1″start”: “node server.js.

If you have a server.js file in the root of your package, then npm the start command to node server.js.

Dependencies

{
"dependencies": {
"express": "~3.0.1",
"sequelize":"latest",
"q":"latest",
"tedious":"latest",
"angular":"latest",
"angular-ui-router": "~0.2.11",
"path":"latest",
"dat-gui":"latest"
}
}

These are specified from simple objects that can map a package name to a version range to stop the version name must contain the version only. If you are looking forward to installing the latest version of a file then you will need to use the latest version name in the place of the old or existing version.

Tilde(~) in Node.js 8s used to signify “Approximately equivalent to version”.

Conclusion

This is a simple task that you can perform to understand the working of the node. Js. It is very easy to work with. If you pay little attention you will be able to ace it and turn it into a career.

Categorized in: