Hello World Program in Node.Js
A hello World program in Node.js
Before I Start with hello world there are few terminologies that you should know as we are gonna use it frequently in almost every exercise we are gonna use them.
Modules
Node.js uses module that are predefined set of function to simplify the creation of complex application as we have libraries in C language.Each module contain some set of functions that is related to the theme of the module like for file system we will use “fs” .We can create and publish our own module as well. To use a predefined module we use “require ()” function ,for eg
var fs = require(‘fs’);
The require function returns the reference to the specific module.In this case ,a reference to the fs(file system) module is stored in fs variable.
NPM
Npm refers to node package manager,it publish,manage and Installs node programs.
Eg : npm npm install mysql@2.0.0-alpha2 to install mysql
Writing your First Application.
Open Notepad and Write Console.log(‘Hello node.js Developers!! we are gonna learn node.js right from the basics.’);
save the file as hello.js
Open node.js command prompt
type node hello.js and press Enter.
I used cd to go the move to the location of the file and we are done with the hello World Now.