Node. js common module collection and node. js collection
It collects some common modules in NodeJS development.
MVC Framework-Express
Express is a lightweight and flexible Nodejs Web application framework that can quickly build websites. The Express framework is built on the built-in Http module of Nodejs, And the Http module is repackaged to implement the actual Web request processing function. It supports multiple front-end templates, such as Jade and EJS. It is a work of T. J, but it has been handed over to other teams for maintenance.
Koa is another masterpiece of T. J., known as the next-generation NodeJS web framework. Using koa to write web applications and combining different generators can avoid repeated and tedious callback function nesting and greatly improve the efficiency of common error handling. Koa does not bind any middleware in the kernel method. It only provides a lightweight and elegant function library, making it easy to write Web applications. Note that:Koa depends on the Node environment that supports generator. Specifically, it is a node> = 0.11.9 environment. After installation, make sure to run the program in harmony mode by using $ node app. js -- harmony or (-- harmony-generators.I personally think it is more reliable to use Express in a formal product.
Rest development-Restify
Restify is a node. js-based REST application framework that supports servers and clients. Restify is more focused on the REST service than express. It removes the template and render functions in express and enhances the use of the REST protocol, version support, and HTTP exception handling.
Hapi is a rich framework used to build applications and services based on Node. js, allowing developers to focus on portable and reusable application logic rather than building the architecture. Built-in input verification, caching, authentication, and other common functions for Web application development are also a good choice for developing rest code.
Front-end template-EJS
EJS is a powerful and easy-to-use front-end template. Express supports EJS better, and its syntax is close to that of front-end developers. In addition, the well-known front-end template is Jade, which is developed by the same author as Express. Express uses the Jade template by default, but its syntax is closer to the back-end language syntax, front-end developers are often difficult to adapt to, but their functions are indeed very powerful.
Database driver-Mongoose
MongoDB and NodeJS should be the best partners, while Mongoose is the object model tool of MongoDB. Through the Mongoose framework, you can easily access MongoDB. Of course, if you have high performance requirements, you can also consider using mongodb, which has relatively few functions and is relatively low-level. In fact, Mongoose is built based on it.
Others: redis and mysql.
Web Socket-Socket. IO
One of the main advantages of NodeJS is high concurrency. Therefore, NodeJS is the ideal choice for Web Socket servers, while Socket. IO is the best choice for Socket modules. It can be used to build chat rooms and customer service systems. Socket. IO not only provides server-side code, but also front-end JS Code, which facilitates Web Socket development and is compatible with browsers that do not support Web Socket.
Log Management-Log4js
Similar to log4j in JAVA, it has functions such as colored console logging and can set the output level. It is easy to use and can be used without complex requirements. Winston is a log module with more powerful functions and more complex functions. It is popular. You can look at this module if you are interested in functions.
HTTP Request
It can be understood as a simplified CURL module that establishes various HTTP requests and supports authorization verification. In fact, there are still many functions that basically meet most of the requirements. Currently, the top few NPM modules are ranked.
Asynchronous Process Control-Async
A large number of asynchronous callback nested estimates in NodeJS pose a headache for many people, especially when multiple asynchronous functions require a certain call sequence, the code is out of control. Async can solve these problems very well, it can synchronize asynchronous processes. Q is another very good choice. It implements the promises interface.
Deployment-forever
Forever can be seen as a nodejs daemon that can start, stop, restart our app, run stably, support high concurrency, simple startup/Stop commands, and support hot deployment, downtime restart, monitoring interface, logs, and cluster environment. Pm2 is a process manager for a Node application with the load balancing function. When you want to use your independent code to take advantage of all the CPUs on all the servers, and ensure that the process is always alive, the load is 0 seconds.
If you want to solve NodeJS server management problems at the operating system level, refer to: Linux System Service upstart
Of course, you can use the supervisor to start the service during development. It can monitor files and automatically restart the service when files are updated. In fact, Forever also has this function.
Project Management
Grunt is an automated build tool. for tasks that need to be repeated repeatedly, such as compression, compilation, unit testing, and linting, the automation tool can reduce your work, simplify your work. After you configure the task correctly, the task runner automatically helps you or your group complete most of the boring work. It also has a large number of plug-ins available for use. I mainly use it for front-end automation.
Bower is another open-source project of twitter. It is developed using nodejs and used for web package management. As a js dependency management tool, it provides an ideal package management method. With the help of npm ideas, it provides us with a comfortable development environment.
Yeoman is developed by Google's team and external contributor team. His goal is to use Grunt (a command line tool for developing task automation) and Bower (A Package Manager for front-end resources such as HTML, CSS, Javascript, and images) to create an easy-to-use workflow for developers. Yeoman aims not only to create workflows for new projects, but also to solve many serious problems faced by front-end development, such as scattered dependencies.
Scheduled task-Cron
Cron is a small scheduled task management module that can meet most of our needs. It supports standard cron patterns and is easy to use with linux cron tab syntax.
Another well-known timing module with powerful functions is Later. It is a little complicated to use it with high functional requirements, unlike cron, which can be used as long as it is used.
Toolkit
Underscore is a JS tool library that provides basic tool functions such as arrays, objects, and functions that can be run simultaneously in browsers and NodeJS environments. We recommend that you use it in each project.
Moment is a date tool library that mainly provides Date Parsing, verification, operations, and formatting. If you need to perform more or more complex operations on the date, it is a good choice. After all, the Date function provided by JS is too weak.
Connect is a collection of middleware, including logs, sessions, cookies, body parser, etc. It does a lot of basic HTTP-related work, and the Express Framework relies on it for work.
Unit Test
Mocha, Karma, Jasmine.
References
- Nodejs articles from scratch
- Node. JS learning Roadmap
- NPM Official Website
How to install external modules of nodeJS
Npm install Module name
For other parameter reference documents, such as-g Global
How can I check whether the external module of Nodejs is installed?
Npm install