What is Node.js
Node.js is an open source, cross-platform runtime environment for server-side and networking applications.
Node.js applications are written in JavaScript, and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD, NonStop and IBM i.
Node.js is a way of running JavaScript on the server.
Node.js (Node) is an I/O environment built on top of Google Chrome’s JavaScript runtime — essentially, a server-side implementation of JavaScript. Node’s asynchronous, event-driven I/O model makes it easy for developers with JavaScript knowledge to build high-performing, scalable, and highly concurrent web applications rapidly and run them in the cloud.
Node.js is simply a JavaScript runtime.
Node.js was built by Ryan Dahl. It is a small “server” built on top of the V8 javascript engine with a thin layer that allows it to talk to the host machine.
Features of Node.js
Following are few of the important features which are making Node.js as the first choice of software architects.
- Aynchronous and Event Driven All APIs of Node.js library are aynchronous that is non-blocking. It essentially means a Node.js based server never waits for a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API call.
- Very Fast Being built on Google Chrome’s V8 JavaScript Engine, Node.js library is very fast in code execution.
- Single Threaded but highly Scalable – Node.js uses a single threaded model with event looping. Event mechanism helps server to respond in a non-bloking ways and makes server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and same program can services much larger number of requests than traditional server like Apache HTTP Server.
- No Buffering – Node.js applications never buffer any data. These applications simply output the data in chunks.
- License – Node.js is released under the MIT license.
Node.js File Structure:
<!– new file structure –>
– app <!– holds all our files for node components (models, routes) –>
—– models
———- todo.js <!– defines the todo model –>
—– routes.js <!– all routes will be handled here –>
– config <!– all our configuration will be here –>
—– database.js
– public <!– holds all our files for our frontend angular application –>
—– core.js <!– all angular code for our app –>
—– index.html <!– main view –>
– package.json <!– npm configuration to install dependencies/modules –>
– server.js <!– Node configuration –>
Advantages And Disadvantages Of Node.js:
Advantages:
- It is fast, easy to learn, scales well and generally lets you unify your client/server logic.
- Handles JSON very well.
- Generally good documentation for the libraries, and a solid community
Disadvantages:
- As others have mentioned, it is not widely used.
- Finding competent developers, example code, working frameworks and feature-complete products is harder than with PHP, Java or .NET.
- The biggest downsides are probably related to the language (JavaScript) itself and the lack of native OO support, as well as the lack of compile-time error detection.
- Once more tooling exists, it will probably start to take off and really mature.
