shivani.js
Version:
Demos for CDAC Training
38 lines (31 loc) • 3.62 kB
Plain Text
NodeJs?
Its a platform for developing JS Apps on server side. In other words, thro Nodejs U can execute JS code without a browser support. Basically its designed on Chrome's V8 JS Engine which makes the required interpretations out of the browser.
In other words, Nodejs provides the features of the Chrome browser inside a command prompt.
Nodejs is downloadable from the www.nodejs.org website where U get the download link to install the NodejS based on the OS that U R working with....
With these features, U can create basic web servers using nodejs, there by opening up on lots of new things on Internet(IOT) which traditional JS didnt do. In this robust environment, U can create apps that performs FileIOs, Database interactions, asynchronous event handlings and creating Web servers so that U could host one or more Web Pages based on HTML in it.
With Angular, there is complete stack development called MEAN Stack popularly used in the market: MongoDB, Express(Module of Nodejs), Angular(UI of the Application) and Nodejs(Environment to host this setup).
Why NODEJS?
Its super fast and highly scalable envinroment.
Builds faster than most of the server side App development tools
Does not need any 3rd party web servers like Apache, IIS or websphere to create Web centric Applications as NodeJS itself can create a Web server for you.
It has 2x requests/ sec which means that the speed of processing each request is 2x times than most of the other web centric Applications.
Js will be the common language used for server, client, middleware so that there is no language based switching during the code execution.
PS: Nodejs is not here to replace the existing web servers like Apache, IIS or whesphere as they have their own benifits and robustness suited for developing rich and large scale web applications, more like an ERP Kind of Apps...
How Nodejs Apps are created?
U dont have UI related tasks in Nodejs environment. Nodejs code is created and distributed as MODULES which are self contained components that will perform the required operations. A module is basically a class that has functions, data which are manipulated by the functions. Most of the time, the modules are self contained with little or no dependencies from external components.
The modules are exported and other jS files consume these modules.
Ways of creating modules:
There are 3 ways to create modules in Nodejs:
Defining it as a global module: U can call the methods without any object creation.
Creating Anonymous modules: Use a reference and call it.
Creating named Modules: More like an object oriented components and can make multiple components in one module.
//Modules are available to the end users using require. Nodejs helps in creating these modules and place them in public repositories called NodePackageManager(NPM). NPM is a large store to post new modules or download existing modules in the world of Nodejs.
To create a nodeJs module that can be consumed by other developers, U should post it inside the NPM repository.
First, UR node module should be exposed as a Nodejs module. Every module must have a config file called package.json
Once the code for the module is created, U should publish this module using a file called package.json.
package.json is created using a command called npm init.
It runs thro the wizard and developer must fill the details appropriately which will generate the package.json file.
To create package.json : npm init
To addNew user: npm adduser
To publish the module : npm publish
To consume the module: npm i packageName.