Node.js operates on a single thread event loop, using non-blocking I/O calls, allowing it to support tens of thousands of concurrent connections without incurring the cost of thread context switching. Node.js relies on the libuv library (written in C) which uses a fixed-sized (multiple) thread pool to handle the non-blocking asynchronous I/O operations.
A downside to the single-threaded approach is that Node.js doesn’t allow vertical scaling by increasing the number of CPU cores of the machine it is running on without using a cluster module (such as pm2). Additionally, the number of threads in the libuv thread pool can be updated. The operating system will distribute these threads across multiple cores. Typically, the number of threads or forked processes should equal the number of CPU cores.
V8 Engine and Node.js bindings
Node.js registers with the operating system so the OS notifies it of connections and issues a callback. Within the Node.js runtime, each connection is a small heap allocation. Traditionally, processes or threads handled each connection. In contrast, Node.js uses an event loop that does not need to be called explicitly. Any function performing I/O must use a callback, and the server automatically enters the event loop at the end of the callback definition. Node.js exits the event loop when there are no further callbacks to be performed.
The process.env global variable is injected by the Node at runtime for your application to use and it represents the state of the system environment your application is in when it starts. Secret variables are stored here rather than in accessible code.
npm is the pre-installed package manager for the Node.js server platform. It installs Node.js programs from the npm registry, organizing the installation and management of third-party Node.js programs. Packages in the npm registry can range from simple helper libraries such as Lodash to task runners such as Grunt.
Npm has a run command that can run scripts defined in the scripts property of a package.json file. It provides additional commands to the CLI, such as npm run test. This functionality reduces the need for third-party tooling like Grunt or Gulp.
You can add even more functionality to NPM scripts by installing open source dev dependencies. npm-run-all can run scripts in parallel (usually multiple tasks are run in sequence with &&). onchange will automatically re-run the task by watching for changes in your code.