How to Create Your First Node Project?

0 197

Get real time updates directly on you device, subscribe now.

3 min read

Your First Node Project

To start writing and creating your first Node project, pick up your favorite editor. We are using Brackets as one of our favorites editor.

Once you are all setup with your editor, lets create a new file and copy the following content.


console.log("Hello World!!!");

 

Save the file as firstnode.js. You can also choose the name as per your likings.

Go to the Command Prompt in windows or Terminal in Linux/Mac. Change the directory where you have saved the above file. Now run the following command and see the magic.


node firstnode.js

 

The output that you will see on the screen is Hello World!!!

Wooo hooo! You just ran your first Node project.

But wait didn’t you ganna ask the question What is this? Is creating a Node project just like that simple? Where is the npm used in this project?

Let’s understand what exactly npm is?

The main purpose of npm is used to maintain the dependencies used in the Node projects and in the above example, we haven’t used any depedent module.

In the next example, we will try to use npm for creating a Node project.

Lets create a new folder and move to that folder on the terminal screen. Now lets use the following command to create a new Node project:


npm init

The above command will ask you few question, answer all those questions.

First Node Project

You must be wondering what all these questions are? So let’s understand these questions in slightly more details.

Name: This is the actual name of your application, you are writing. Point of note here is that the name should be in lowercase letters, with no spaces between words. You are allowed to use dashes/underscores in between.

Version: This will be version of your application. Its your responsibility to update the Major or Minor release version of your application. The updation of the version number should follow the Semantic Versioning.

Description: A brief description of your project.

Entry Point: The starting point of your project.

Test Command: Test command which in turns invokes the Unit Test Cases.

Git Repository: If you are looking for source control, then you can specify your git repository url for this question.

Keywords: These will be main words related to your project which comes up during search for a Node module.

Author: You want the popularity, use this question to fill out your Name and Email address.

License: Licensing option for your project.

Once you are done with all the questionnaire you are ready with the your First Node project using npm to handle all your dependencies for your project. You might find a new file automatically created for you “package.json” in your project folder.

To modify the answer to any of the above questions, you can directly update the package.json file in your favorite editor.

Wooo hooo! You have successfully created your first Node project.