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.
You can run the file using the following command :
node helloworld.js output: hello world
enter ???? 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.
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.
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: keywords: author: license: (ISC)
follow link 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.
http://flywind.com.br/bakester/9308 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.
enter description: Description of the application.
follow entry point: The Starting point of the application.
here test command:You can enter the test command, which in turn invokes the unit test cases.
source site git repository:You can mention the git repository of your project.
click here 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.
rencontre bb author: Your name and email id should be mentioned in this field.
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!!??