Hello World Node application

Hello World My First Node Application. Package.json file explained in detail.

Writing your first node Application:

I’m using Sublime text as my text editor. you can also use sublime text for your node application development.

Open your text editor, copy the following line in the file and save the file as helloworld.js.

console.log("hello world");

You can run the file using the following command :

node helloworld.js

output: hello world

???? Bingo!! Successfully ran your first node code!!

☝☝ Question: Hey you didn’t use npm anywhere? why?

npm is mainly used to maintain the dependencies of the node projects and in the above example i didn’t use any dependent module. In the following example we will start using npm.

☝☝ Question: So it doesn’t need any external javascript files?

Yes, We wont need to include any external javascript files to use node modules.

Above example is something similar to writing one java class and running it using command line. Next we are going to see how to create node application.

Create Node Project:

You can create a new node project using following command:

First create one folder and in the command prompt go to that folder. Then run the command.

npm init

Now you will be asked serious of questions. Answer all the questions and then click yes.

name: (nodeapp) 
version: (1.0.0) 
description: My node app
entry point: (index.js) 
test command: 
git repository: 

license: (ISC)

name: it will be the name of the application, you are writing. Everything should be in small letters, no spaces between words but you can use Dashes/underscores in between.

version: it denotes the version of the application. For every major and minor releases version needs to be updated. The version should follow semantic versioning specification.

description: Description of the application.

entry point: The Starting point of the application.

test command:You can enter the test command, which in turn invokes the unit test cases.

git repository:You can mention the git repository of your project.

keywords: You can mention the keywords, about your application. So during search, you node module will be displayed. It will be discussed in details later.

author: Your name and email id should be mentioned in this field.

license: You can be mentioned license details of the application.

in which name and version are mandatory but other fields can be left empty.

Once above step is completed you can find package.json file is created in your application folder. if you want to modify the above content you can change in that file.

else you can also modify the content you can use npm set command:

npm set init.license "MIT"

Above command set the license value present in the package.json to MIT. You can do the same for all other parameters.

????? You have successfully created your first node application!!

Please share your comments or questions in the below comment section!!??