Node.js is a cross-platform JavaScript runtime environment that can run JavaScript code on the server side.
Most of Node's modules are written in JavaScript. Before Node appeared, JS was usually used as a client-side programming language, and programs written in JS were often run on the user's browser.
Node.js can be understood as a server that has implemented functions. It uses the command line to import the programmer's js code that has achieved the function into the server to run and get the result.
Programmers can also use CoffeeScript, TypeScript, Dart language, and other programming languages that can be compiled into JavaScript language to write functional code, and then hand it over to Node.js to execute.
Node is single-threaded when processing requests (when programmers use the node command to execute code), but it has an I/O thread pool in the background.
Node is an implementation of the CommonJS specification.
CommonJS specification
The CommonJS specification was proposed mainly to make up for the current lack of modular standards for Js.
CommonJS's definition of a module is very simple, with only three aspects: module reference, module definition, module identification
The realization of the CommonJS specification by Nodejs is to achieve the above three aspects.
Modular
In node, every js file written by a programmer is a module.
In Node, the js code in each js file runs independently in a function instead of the global scope, so the variables and functions in one module cannot be accessed in other modules.
In node, external modules are introduced through the require() function. This method can pass a file path as a parameter, and node will automatically introduce external modules according to the path. Note: If you use a relative path, it must start with "." or "..".
After the module is imported using require(), the function will return an object, which represents the imported module, through which the methods or variables modified by exports in the imported module can be obtained.