Enhance your career prospects with our Data Science TrainingKNOW MORE
Node.js comes with an in-built package manager called NPM. The idea of NPM is to provide modules publicly available, reusable, easy installation via an online repository with version and dependency management.
Say we want to develop a server-side application, and let's see what does NPM modules offer us in building a full-fledged application. For clients to consume, we need to build APIs and ExpressJS helps us in achieving it.Express.js is actually a web development framework helps in building high performant APIs.
Express has an inbuilt routing mechanism i.e. express. Router to create modular, mountable route handlers. A Router instance is a complete middleware and routing system; for this reason, it is often referred to as a “mini-app”.
Now to improve performance, we can rely on the ‘Connect’ module which provides a list of middleware plugins. Since it is an extensible HTTP server framework, it can serve as a base to express.
Say if we want to return an HTML for a route/API and this view is dynamic in nature based on parameters. We can build some templates and render them accordingly. Express provides support to many template engines and ‘PUG’(known earlier as jade) is one of the popular ones.
If we are developing an application that needs to keep polling our server from different clients. Sockets provide a bi-directional communication channel between client and server. Socket.io and sockjs help in achieving this.
Say if our backend is a document-orienteddatabase like mongoDB, then we have node modules i.e. mongodb and mongojs which provide high-level APIs on top of mongoDB core database objects. Most of the time, interaction with DB is asynchronous in nature. For that, we can rely on the async module along with bluebird to program with promises for good performance.
Sometimes, we see unexpected failures when the server is deployed to production. To ensure it runs continuously we can use forever module utilities. And lodash, underscore, lazy.js provides some nice utility functions which are compatible with ES6 also. To support globalization and localization in a display of timestamps, validating, formatting, etc we can rely on Moment.js module.
If we want our application to scale then express might have few limitations. So here we can use a hapi module which is built based on the express framework. We can use different DBs like MySQL, MongoDB, and Postgres. It acts as a layer between the node and your application logic. It is a robust plugin system allowing us to add new features.
As we keep evolving our application, we might need to build new functionality, component or wrappers (say for interaction with DB). Before building anything new, it is always suggested to check the NPM store. Because of open-source nature, we get to solve problems ahead before they arise but be cautious of compliance usage rules specific to your organization.