Node.js helps the developers to create the server side code along with the client side code without using any other additional languages.
Node.js provides a set of asynchronous I/O primitives in its standard library, libraries in Node.js are written using non-blocking paradigms.
ECMAScript standards and ECMAScript versions can be used according to the preference of the developer.
Node.js is a server side environment and is designed to increase the scalability of the web applications and to provide dynamic web page. It’s run time environment is designed to process the incoming request using the event loop structure. It process the request using single threaded Just like other programming languages it also includes Variables, Types, Classes, Functions, Loops, Arrays, expressions. In addition Strict mode, arrow functions are also added.
Node.js has different types of Core modules and also allows to create Local Modules according to the need of the developer and application. Examples for core modules are http, url, path, util. File system and its operations are performed using “fs” module. After creating the local module we need to export it. The object module.export is used to export the module. The modules need to be loaded using require() function.
A framework is a collection of various libraries and tools which is used to create the software application. It includes other frameworks, extend the properties and functionalities to increase the productivity.
Node package manager is represented with the command “npm” it is used to install the dependencies.
> npm install json –save
> npm install errorhandler –save
> npm install logger –save
Just like other programming languages it also includes Variables, Types, Classes, Functions, Loops, Arrays, expressions. In addition Strict mode, arrow functions are also added .
Node.js supports both relational database or NoSql database.
for relational database – MySQL, MS SQL SERVER, SQLite
for NoSQL database – MongoDB, Couch DB
Node.js File System
Node.js includes fs module to access the files. The fs module is responsible for all the asynchronous or synchronous file I/O operations.
Different methods are used to perform the file operations. Some examples are readFile(), writeFile(), appendFile(), unlinkFile(), other parameters and flags are used according to the need.
Debug Node.js Application
In Node.js we need to do debugging in the command line. Debugging process can be done as a step by step process.
We need to start the command with the keyword “inspect” to start the debugging process.
Node.js Web Server
The web server will handle all the http requests for the web application. In Node.js we can create our own web server which will handle HTTP requests asynchronously.
The http module is used to create the web server, then the createServer() method is used, next callback function will be used handle the request and response in the web server. Call listen will handle all incoming requests of the web server.
Node.js console is an object and is used to print different levels of messages.