node js website development


(node js website development)Node.js Since release,Has become one of the important breakfare of the industry。Uber、Medium、PayPal And Wal-Mart and other large companies,Trims of technology stacks Node.js。Node.js Support for powerful applications,For example, in real time App、video / Text chat engine、social media App Wait,Currently become a skill that developers。This article is based on its own implementation experience.,Give one Node.js Learning road map。It is recommended that developers consider deeply master Node.js Before,Must be clearly constructed to build the goal,Otherwise, it is easy to waste halfway。Target-oriented helps focus on key skills in learning,Not fingering, whether it is worth learning。

Essential skills


For a front-end developer,When considering mastering the back-end skill,No need to spend a lot of energy learning JavaScript。For complete white,If you want to master it as short as possible Node.js,Before deeply in-depth, you must understand the following concept.:

  • Arrow function(Arrow Functions)
  • Types of(Types)
  • expression(Expressions)
  • function(Functions)
  • grammar structure(Lexical Structures)
  • this
  • cycle(Loops)Scope(Scope)
  • Array object(Arrays)
  • Field template(Template Literals)
  • Strict mode(Strict Mode)
  • ES6/ES7

also,Node.js Negative asynchronous programming processing,Recommended to master the following concept:

(node js website development)

  • Timer(Timers)
  • Promises
  • Closure(Closures)
  • Event cycle(Event Loop)
  • Asynchronous programming(Async programming)And callback(callbacks)

npm Package management

(node js website development)

Node Package management(Node Package Manager,npm)Provide current largest registration software library,Where is provided 80 $ 100,000 packages。use correctly npm,Negatively reduce the complexity of package management,Very easy to solve the problem of application development。

(node js website development)

npm Provide three constituent modules:

  • Command line interface(Command Line Interface,CLI):CLI Is most developer's preferred way,Provide local terminal environment。
  • Register Software Library(Registry):Provide large-scale open JavaScript Software and element information database。
  • Web Site:Find new packages,And provide some other npm Function。

npm Also manage the code and dependence of each version。Use npx,You can run the package without downloading the package。

Node.js Basic knowledge

Event transmitter(Event Emitter):Be Node.js Object,Event Emitter Send a message after the operation is executed,Trigger a specific event。Developers can also write code,monitor Event Emitter Incident。E.g,Once a specific front end operation is completed,Mouse click、Buttons and mouse movements such as interaction,Need to further process in the backend。At this time Node.js Environmental use EventEmitter kind,Build the corresponding event processing module,Used to handle operational events。

Callback(Callback):The callback is a function called after the specific task is executed.,Do not affect other code,Avoiding asynchronous processing occurs。Given Node.js A large number of asynchronous tasks,Therefore, the callback is everywhere.。The callback is the key to realizing the application seamless,The operation mechanism is shown below:

node js website development

Buffer kind:Designed to handle primitive binary data Node.js kind,operate V8 The memory allocated outside the engine。Buffer Class implementation as an array of unmodable sizes,And provide a set of binary data operation methods。E.g,For the scope of the scope 0 arrive 255 Semiology between the byte value,use console.log() Output Buffer Example,Will give a series of hexadecimal values。

Module system(Module System):use Node.js Module provided by the ecosystem,Some complex functions can be implemented。Module is multiplexed JavaScript Code,Implement specific functions。

Development skills

Version management system:master git、GitHub Use。In development,It should be avoided to avoid the change caused by the cross-modification code.。therefore,Release control system management is required in large projects。Be familiar with the use of version control systems,Developers should have solid foundation knowledge。

HTTP/HTTPS protocol:Excellent Node.js Developer,Basic knowledge should be included in the transmission protocol data transmission,Because each backend developers need to understand in-depth understanding HTTP/HTTPS Working mechanism。HTTPS Use TLS(Transport Layer Security)Encryption protocol encrypted communication。There are a lot of knowledge points to learn in the backend environment.,This for Web Xiaobai is quite difficult。in short,basic Web Communication mainly includes six request methods:

  • GET: Get the representation of resources;
  • POST: Create new resources;
  • PUT: Update resources;
  • PATCH: Partial revision of resources;
  • DELETE: delete URL Specified resource
  • OPTIONS: Request URL/ Communication supported by the server。
(node js website development)

Web frame

Notice:This article only lists some of the recommendations Web frame。use Node.js When building a personal project,To reduce learning difficulty,Recommended a framework,Otherwise, learning is difficult。

Express.js:Provide minimization interfaces and tools required to build applications,Very flexible,Large amount npm Module can be inserted directly Expresss use。

(node js website development)

Meteor.js:A kind of construction JavaScript Application of all-pass framework,Provide built-in MongoDB,support GraphQL。run meteor create myapp,It can generate one with MongoDB Rear end HTML/JavaScript page。use Meteor.js Can effectively help reduce project development time,And simplify project maintenance。Of course, if you just build a simple Web application,Still recommended Express。

(node js website development)

Sails.js:A support for fast build REST API、Single page application(SPA)In real time APP of MVC frame。If the developer considers some important skills,For example WebSockets Support real-time operation,Use the agreement programming(convention over configuration)Method, etc.,Recommended Sails.js。

Koa.js:If developers consider building a decent tested、Easy maintenance robust application,Koa.js Undoubtedly a good choice。Koa Application is implemented as an object containing an array of middleware functions,Where functions are implemented in a stack。

Nest.js:The frame is inherited. Angular Ideil,use TypeScript Construct,And used at the bottom layer Express.js,Therefore, compatible with most Express Middleware。Nest Provide a good modular structure,Code organization in different modules,Further, construct efficient、Good extension。

Database management

Learn Node.js Need to master a lot of backend skills。For a small white,Start selecting MySQL And other databases。Only the basic knowledge of the backend system design,Can be based on the needs of the project,Consider MySQL Wait for basic SQL Database outside the database。

Notice:Relationship database is still mainstream。E.g,In modeling products、analogy、The label is still mainly used for the relationship table structure.。Similar to spreadsheets,Relational table consists of rows and columns。

Relationship database management system

SQL Server:Microsoft's Relationship Database Product,Support standard ANSI SQL,Also provide products unique SQL accomplish。

MySQL:An excellent relational database management system,Timeout Oracle Open source backend software,Flexibility with request improvement code。MySQL Can be replaced very well Oracle、Microsoft SQL server Waitage business database products。

PostgreSQL:Open source products supported by large-scale development teams,Can operate Linux、UNIX and Windows Most mainstream operating systems。PostgreSQL Support most standards SQL Inquire,Also provide complex SQL Inquire、Foreign key、trigger、Transaction、MVCC、Flow completion characteristics。

MariaDB:MySQL Improvement version,A variety of features have been built in addition、Safety and performance improvement。in short,MariaDB Superior MySQL,Recommended in large applications MariaDB。E.g,MariaDB Large connection pool supports more than 20 Wan's concurrent connection,Superiority MySQL。

(node js website development)

Cloud Database Service

(node js website development)

Azure CosmosDB:Global distributed database service,Support remote management data。For large applications,Cloud database has advantages in extension and manageability。Microsoft Azure Expandable and distributed capabilities,Supports multiple data models on the same rear end,Simultaneous use for documentation、Key value、Relationship and graph model。This service does not depend on any mode,Therefore it can be called NoSQL database,But use support ACID Transaction query language。

(node js website development)

Amazon DynamoDB:Very suitable for SQL Experience user,Provide full hosting NoSQL Database service,High performance,predictable,Extensibility is very good。DynamoDB Support to create a relational table,Can store and retrieve any size data,Request for any service level。

(node js website development)

NoSQL database

MongoDB:Documentary NoSQL database,Suitable for large-scale data storage。Similar to the table is the basis of the relational database,MongoDB Use collection(Collection)And documentation(Document)。in,Documentation contains key value pairs,Yes MongoDB Basic data unit。Collection contains a series of documents and functions,Table in the counterpart database。

Redis:Can be used in database、Cache and message proxy(Message Broker)。Redis Use string、Hash、List、gather、bitmap、hyperloglog And data structures such as time and space index,Store data in key value。The following example:

Suppose the application must handle different operations of authorized users。Verify user identity each time,All must be authorized to access access control modules in applications。There are many scenarios to achieve such security mechanisms.。E.g,standard JOSE(JavaScript Object signature and encryption)Framework ensures the security of application data。But in the face of multiple authorization,Application is also difficult to expand。In addition to sending a licensed list to the user,Another solution is to authorize the user in some form of database storage。Authorization with key value(Token)Form provided,Users must provide key values for verification。

Apache Cassandra:Facebook Created high scalable、High performance distributed database,Designed to physically distributed massive data,Realize storage without single-point fault。Unlike other relational database systems,Cassandra Refer to the distributed design Amazon DynamoDB,Data model use Google BigTable。

LiteDB:A super lightweight、High-performance .NET NoSQL Embedding database,Realize the server-free document storage。LiteDB Used in small desktop applications、Web application,A separate database can be established according to each account of each user。

search engine

Notice:Why do I need to understand search engine technology?,The following example。If you use Google Search Engine,It is itself a complete Web application。for Solr and ElasticSearch Wait frame,They create indexes all types of datasets,Haracterly supplies search functions。Solr Search engine website for millions of users。

ElasticSearch:A kind of Apache Lucene use Java Development search and analysis engine,Real-time storage and analysis of massive data。Its high performance comes from a search index rather than text,Core based on structured document,Non-relations and patterns,Offer rich REST API Store and search data。ElasticSearch It can be considered a handling JSON Request and return JSON Data server。

Solr:Provide a field search、Boolean inquiry、Phrase、Fuzzy query、Syntax check、Senior real-time search function such as automatic filling。


Notice:Cache uses memory file copies,Reduce network call,Provide a faster network response。

Memory cache

(node js website development)

Most of this technology uses the memory of the server,Therefore, it is often referred to as memory cache。Part of the server is used as a cache,Store all the data required to reduce application network calls。Node.js Node cache provided(node-cache)And memory cache(memory-cache)Software library,Very good Node Memory cache on the server。

Distributed cache

Distributed cache integrates multiple network memory into a single memory data storage,Further, for cache final data,Provide quick access to data。This technology is especially suitable for large-scale data and a large number of network calls.,Cache capacity increase and expansion by adding more servers in the cluster。Redis It is currently the most widely used Distributed memory,Recommend to know more Memcached。

(node js website development)

node js website development(node js website development)

Template engine

Template engine supports using static template files in application development,And replace the variables in the template file at runtime as the actual value,Generate sent to customers HTML document。Some of the widely used template engines are listed below.。

  • Mustache.js
  • Handlebars
  • EJS

Real-time communication developed in starting contact with backend,To understanding Real-time communication needs to add a lot of knowledge,Main underlying logic between clients and servers。 Support for bidirectional data between customers and servers,It can be seen as a simultaneous data flow of real-time communication between two terminals.。This requires customers to support browser Socket.IO,And the server is inherited Socket.IO Software package,In turn, the data can be JSON Send。

API Client


exist REST Previously proposed,API Use remote procedure call(RPC)Develop,Similar to the local execution。Many technologies have been used similar to RPC Technological stack,Not fundamentally solved,until REST Build a better way to build Web of API。

REST Architecture uses basic HTTP Call for communication,Avoid using COBRA、COM +,RPC Equal complex way communication。exist REST middle,Call is based on the message,rely HTTP Standard description message。exist Node.js Ecology,Recommended Use node-rest-client and Axios。These two software libraries are fast Web Applies provide good support。


GraphQL Can be replaced very well REST。It uses API Give priority to accurately provide the requested data,Is a flexible and friendly alternative to developers,be usable GraphiQL IDE deploy。GraphQL Have multiple advantages,Including the addition and disable data field without affecting existing query,And support multiple ways API。


Unit test framework

Unit test implementation of isolation testing of each unit and components。in,The unit can be the minimum test code portion in the application。Below Node.js The best unit test framework:

  • Jest:By Facebook Provided test framework,Widely used due to its simpleness。Jest It has the best documentation compared to all other test frameworks,Support parallel test,This means you can run each test using separate processes.,Maximize performance。
  • Mocha:for Node Application provides the original standard unit test framework,Support callback and other asynchronous operations,Support use high scalable and custom assertion Promise。
  • Chai:Support Mocha Use,Can be Node.js of TDD/BDD Assertion library,Match anything based on JavaScript Test frame。

Simulation test(Mocking)

The smaller the size of the unit test, the better,And perform as little as possible。But in some cases,Test objects have dependence on other objects。

E.g,For need to be used with a domain server or Web Service Communication object,Unable to perform fast、Lightweight test,It is necessary at this time. Mocking test。run Mocking Test does not require any actual database,Or any type of connection,Returns the object given to the expected result。Mocking Test only some basic objects,Simulation gives actual test results,So you can get rid of all limitations faster。

Recommended reading: The following information describes how to use Sinon and Jasmine accomplish Mocking test:

  • Sinon
  • Jasmine
(node js website development)

Node.js Soft library recommended:

  • Async.js
  • PM2
  • Commander.js
  • Nodemailer