Home > Web Front-end > JS Tutorial > Summarize some modules commonly used in Nodejs development

Summarize some modules commonly used in Nodejs development

青灯夜游
Release: 2021-04-15 10:16:33
forward
2100 people have browsed it

This article will introduce to you some modules commonly used in Nodejs development. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Summarize some modules commonly used in Nodejs development

Collects some modules commonly used in NodeJS development.

MVC Framework - Express

##Express is a lightweight and flexible Nodejs web application framework that can be quickly built website. The Express framework is built on the built-in Http module of Nodejs and repackages the Http module to implement the function of Web request processing. It supports a variety of front-end templates, such as Jade, EJS, etc. It is the work of T.J., but it has been maintained by other teams. [Related recommendation: "

nodejs Tutorial"]

Koa is another work of T.J. It is known as the next generation NodeJS web framework. Using koa to write web applications, by combining different generators, you can avoid repeated and cumbersome 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 that makes writing web applications easy. It should be noted that koa relies on the Node environment that supports generators. To be precise, it is the environment of node >= 0.11.9. After the installation is complete, you should make sure to run the program using $ node app.js --harmony or (--harmony-generators) i.e., harmony mode. Personally, I feel that if it is a formal product, it is more reliable to use Express.

Rest Development- Restify##restify is a REST application framework based on Nodejs, supporting server and client . Restify is more focused on REST services than express, removing the template, render and other functions in express. At the same time, it strengthens the use of REST protocol, versioning support, and HTTP exception handling.

hapi

is a rich framework for building Node.js-based applications and services, allowing developers to focus on portable and reusable application logic rather than building architecture. It has built-in input validation, caching, authentication and other functions commonly used in web application development. It is also a good choice for developing rest code.

Front-end template -

EJS##EJS is a powerful and easy-to-use front-end template. Express is very suitable for EJS The support is relatively good, and its syntax is closer to how front-end developers use it. In addition, the more famous front-end template is Jade

, which was developed by the same author as Express. Express uses the Jade template by default, but its syntax is closer to the syntax of the back-end language, and there are many front-end developers. It's hard to get used to, but it's really powerful.

Database driver -

Mongoose##MongoDB and NodeJS should be the best partners, and Mongoose is the object model tool of MongoDB. Through the Mongoose framework, you can perform very convenient operations to access MongoDB. Of course, if you have very high performance requirements, you can also consider using

mongodb

, which has relatively few functions and is relatively low-level. In fact, Mongoose is built on it. Others: redis,

mysql

. Web Socket -

Socket.IOOne of the main advantages of NodeJS is high concurrency, so NodeJS is Web Socket The ideal choice for servers, and Socket.IO is the best choice for Socket modules, which can be used to build chat rooms, customer service systems, etc. Socket.IO not only provides server-side code, but also provides front-end JS code, which makes Web Socket development very convenient. At the same time, it is compatible with browsers that do not support Web Socket.

Log management- Log4js

is similar to log4j in JAVA, with functions such as colored console logging and the ability to set output levels. Simple and easy to use, enough to use if there are no complex requirements. winston is a log module with more powerful and complex functions. It is relatively popular. Those who are pursuing functions can take a look at this module.

HTTP call Request

can be understood as a simplified CURL module that establishes various HTTP requests and supports authorization Verification, in fact, there are still many functions, which basically meet most needs. Currently among the top NPM modules.

Asynchronous process control - Async

##The large number of asynchronous callback nesting in NodeJS is estimated to give many people a headache, especially When multiple asynchronous functions require a certain calling sequence, the code gets out of control. Async can solve these problems very well. It can synchronize the asynchronous process.

Q is another very good choice, it implements the promises interface.

Deployment- forever

#forever

can be seen as a nodejs daemon. Able to start, stop, and restart our app application, run stably, support high concurrency, simple start/stop commands, support hot deployment, restart after downtime, monitoring interface and logs, and cluster environment. pm2 is a process manager for Node applications with load balancing function. When you want your standalone code to utilize all CPUs on all servers and keep the process alive, 0 second reloads. If you want to solve the NodeJS server management problem from the operating system level, you can refer to:

Linux system service upstart

Of course you can use

supervisor during development

Start the service, which can monitor files and automatically restart the service when there are file updates. In fact, Forever also has this function.

Project Management

grunt

is an automated build tool for tasks that need to be repeated over and over again, such as minification, compilation, and units. For testing, linting, etc., automated tools can reduce your labor and simplify your work. When you configure the task correctly, the task runner will automatically complete most of the boring work for you or your team. And it has a large number of plug-ins available. I mainly use it for front-end automated processing.

bower

is another open source project of Twitter, developed using nodejs and used for web package management. As a js dependency management tool, it provides an ideal package management method, using some ideas of npm, to provide us with a comfortable development environment.

yeoman

was developed by Google's team in collaboration with a team of external contributors. Its goal is to use Grunt (a command line tool for automating development tasks) and Bower (an HTML, A package manager for front-end resources such as CSS, Javascript, and images) that creates an easy-to-use workflow for developers. The purpose of Yeoman is not only to establish workflows for new projects, but also to solve many serious problems faced by front-end development, such as scattered dependencies.

Scheduled tasks -

Cron##cron is a small scheduled task management module that can satisfy most of our needs Requirements, it supports standard cron patterns, and you can easily get started if you are familiar with the syntax of Linux cron tab.

Another well-known and powerful timing module is

Later

. It can be used for those with higher functional requirements. The disadvantage of later is that it is a bit complicated. Unlike cron, it only needs to be used. Will use it.

Toolkit

underscore is a JS tool library that mainly provides some basic tool functions for arrays, objects, functions, etc., which can be used in the browser at the same time and run in NodeJS environment. Recommended for use in every project.

moment is a date tool library that mainly provides parsing, verification, operation and formatting of dates. If you need to perform more operations or more complex operations on dates, Then it is a good choice, after all, the Date function that comes with JS is too weak.

Connect is a collection of middleware, including log, session, cookie, body parser, etc. It does a lot of basic work related to HTTP, and the Express framework relies on it. carrying out work.

Unit Test

Mocha,Karma,Jasmine.

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of Summarize some modules commonly used in Nodejs development. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template