UNPKG

nodejs-dac-examples

Version:

38 lines (30 loc) 3.55 kB
Limitations of Javascript: Js is not designed for IO operations, so its not suited for Server side programming. For server side programming, where apps need to interact with files, User io, Databases and many other storage devics U must use programming languages like ASP, JSP, PHP, ASP.NET and many others. Nodejs is a JavaScript Library for providing Server side features to UR javascript. Its basically a platform built on Chrome's V8 JS engine which when installed can be interacted with Command prompt. U could now run JS code from the command prompt which was earlier used only with the support of a browser. Features of Nodejs: It allows to run JS on the server side which makes Web Apps creatable using JS alone. U dont need any additional Server side technology like PHP, JSP or any of that kind. It is a platform built on Chrome's Javascript Runtime(Google V8 Engine) for easily building fast internet based Apps. It is server side JS Framework. It uses CommonJs Module system where JS code is exported as Modules. Each module is a self contained unit with data and functions. It also supports ECMA Script 6, the latest version of JS. This was created by Ryan Dahl, an employee from JoYant Technlogies in 2009 and is currently maintained by Joyant Technologies. nodejs uses event loop, a mechanism of executing the code as an event driven programming model associating the event handlers as async functions. Each Event handler is an asynchronous method, which means that UR app will not be blocked till the functionality is achieved. Nodejs is a single threaded Application environment. All the nodejs code is created and distributed in the form of modules. Each module is a self contained unit with methods, data and events in it. U can reference the module in another module and make it run. Nodejs is supported by an Open source Repository of Code called NPM. NPM stands for Node Package Manager. NPM is a repository of various tested node modules that can be utilized by Nodejs Developers across the world. U too could add UR modules to the NPM and allow other developers to use UR code(Module). NPM has a lot of such node modules available for the developers to consume the modules in their Applicatoins and much of the App developement will be reusable code. Steps for runing JS in Node: Create the JS file and develop the required logic. Run the command-> node JSfile.js to make the app execute... For js files to be included in another JS file, U should create UR code as a node module and with that module U could use that module in the current js file and execute it. Node gives module.exports API to create a module in Nodejs and to be imported into another js file. There are 3 ways to export a module in Nodejs. Anonymous Module: module.exports = (function{})(); Named Module: module.exports.cart = function(){}; Composite Module: An extension of module.exports which contain more than one components in it. Nodejs gives us a host of prebuilt modules which can be used for developing real time nodejs applications. This include features like File IO operations, Web server rendering, OS related activities, String manipulations and many more. fs is a module for FileSystem to perform File IO operations. os is a mdoule for getting info about the OS UR app is executed. util is a module for string formating. http is a module for performing http services like Web server, REST Services and many more. events is a module for performing event handling in UR code.