Node.js

Node.js JavaScript 运行时。「Node.js JavaScript runtime.」

Github stars Tracking Chart

Node.js®是一个基于Chrome V8 JavaScript引擎构建的JavaScript运行环境。Node.js使用事件驱动的非阻塞I/O模型,使其轻便且高效。 Node.js的包生态系统 —— npm,是世界上最大的开源库生态系统。

Node.js项目由Node.js Foundation支持。 贡献、政策和发布是根据公开治理模式进行管理的。

作为异步事件驱动的JavaScript运行环境,Node被设计为构建可扩展的网络应用程序。 在下面的“hello world”示例中,可以同时处理许多连接。 在每个连接上,回调被触发,但如果没有工作要完成,Nodec则在睡眠。

const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {  
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});
server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

这与使用OS线程的今天更常见的并发模型形成对比。 基于线程的网络相对低效,非常难以使用。 此外,由于没有锁,Node的用户不用担心死锁。 Node几乎没有功能直接执行I/O,所以进程永远不会阻止。 因为没有阻止,可扩展系统在Node中开发非常合理。

Node在设计上类似于Ruby's Event Machine或Python Twisted等系统,并受其影响。 Node将事件模型进一步。 它将事件循环呈现为运行时构造而不是库。 在其他系统中总是有一个阻塞调用来启动事件循环。 通常行为是通过脚本开头的回调定义的,最后通过像EventMachine::run()这样的阻塞调用启动服务器。 在Node中没有这样的start-the-event-loop调用。 执行输入脚本后,Node只需输入事件循环。 当没有更多的回调执行时,Node退出事件循环。 这种行为就像浏览器JavaScript - 事件循环是从用户隐藏的。

HTTP是Node中的一流公民,设计有流媒体和低延迟。 这使得Node非常适合于Web库或框架的基础。

只是因为Node是没有线程的设计,并不意味着你不能利用你的环境中的多个核心。 可以通过使用Node的child_process.fork()API来产生子进程,并且被设计为易于与之通信。 建立在同一个接口上的是集群模块,它允许您在进程之间共享套接字,以实现对内核的负载平衡。(原文:https://nodejs.org/en/about/

Overview

Name With Ownernodejs/node
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 13)
PlatformDocker, Linux, Mac, Windows, Unix-like
License:Other
Release Count828
Last Release Namev22.0.0 (Posted on 2024-04-24 15:14:50)
First Release Namev0.0.1 (Posted on 2009-05-27 18:19:00)
Created At2014-11-26 19:57:11
Pushed At2024-04-28 16:51:45
Last Commit At
Stargazers Count103.8k
Watchers Count2.9k
Fork Count27.9k
Commits Count41.2k
Has Issues Enabled
Issues Count17550
Issue Open Count1578
Pull Requests Count7867
Pull Requests Open Count559
Pull Requests Close Count24784
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Node.js

Node.js is an open-source, cross-platform JavaScript runtime environment.

For information on using Node.js, see the Node.js website.

The Node.js project uses an open governance model. The
OpenJS Foundation provides support for the project.

Contributors are expected to act in a collaborative manner to move
the project forward. We encourage the constructive exchange of contrary
opinions and compromise. The TSC
reserves the right to limit or block contributors who repeatedly act in ways
that discourage, exhaust, or otherwise negatively affect other participants.

This project has a Code of Conduct.

Table of contents

Support

Looking for help? Check out the
instructions for getting support.

Release types

  • Current: Under active development. Code for the Current release is in the
    branch for its major version number (for example,
    v15.x). Node.js releases a new
    major version every 6 months, allowing for breaking changes. This happens in
    April and October every year. Releases appearing each October have a support
    life of 8 months. Releases appearing each April convert to LTS (see below)
    each October.
  • LTS: Releases that receive Long Term Support, with a focus on stability
    and security. Every even-numbered major version will become an LTS release.
    LTS releases receive 12 months of Active LTS support and a further 18 months
    of Maintenance. LTS release lines have alphabetically-ordered code names,
    beginning with v4 Argon. There are no breaking changes or feature additions,
    except in some special circumstances.
  • Nightly: Code from the Current branch built every 24-hours when there are
    changes. Use with caution.

Current and LTS releases follow semantic versioning. A
member of the Release Team signs each Current and LTS release.
For more information, see the
Release README.

Download

Binaries, installers, and source tarballs are available at
https://nodejs.org/en/download/.

Current and LTS releases

https://nodejs.org/download/release/

The latest directory is an
alias for the latest Current release. The latest-codename directory is an
alias for the latest release from an LTS line. For example, the
latest-fermium directory
contains the latest Fermium (Node.js 14) release.

Nightly releases

https://nodejs.org/download/nightly/

Each directory name and filename contains a date (in UTC) and the commit
SHA at the HEAD of the release.

API documentation

Documentation for the latest Current release is at https://nodejs.org/api/.
Version-specific documentation is available in each release directory in the
docs subdirectory. Version-specific documentation is also at
https://nodejs.org/download/docs/.

Verifying binaries

Download directories contain a SHASUMS256.txt file with SHA checksums for the
files.

To download SHASUMS256.txt using curl:

$ curl -O https://nodejs.org/dist/vx.y.z/SHASUMS256.txt

To check that a downloaded file matches the checksum, run
it through sha256sum with a command such as:

$ grep node-vx.y.z.tar.gz SHASUMS256.txt | sha256sum -c -

For Current and LTS, the GPG detached signature of SHASUMS256.txt is in
SHASUMS256.txt.sig. You can use it with gpg to verify the integrity of
SHASUMS256.txt. You will first need to import
the GPG keys of individuals authorized to create releases. To
import the keys:

$ gpg --keyserver hkps://keys.openpgp.org --recv-keys 4ED778F539E3634C779C87C6D7062848A1AB005C

See Release keys for a script to import active release keys.

Next, download the SHASUMS256.txt.sig for the release:

$ curl -O https://nodejs.org/dist/vx.y.z/SHASUMS256.txt.sig

Then use gpg --verify SHASUMS256.txt.sig SHASUMS256.txt to verify
the file's signature.

Building Node.js

See BUILDING.md for instructions on how to build Node.js from
source and a list of supported platforms.

Security

For information on reporting security vulnerabilities in Node.js, see
SECURITY.md.

Contributing to Node.js

Current project team members

For information about the governance of the Node.js project, see
GOVERNANCE.md.

TSC (Technical Steering Committee)

TSC emeriti

Collaborators

Collaborator emeriti

Collaborators follow the Collaborator Guide in
maintaining the Node.js project.

Triagers

Triagers follow the Triage Guide when
responding to new issues.

Release keys

Primary GPG keys for Node.js Releasers (some Releasers sign with subkeys):

To import the full set of trusted release keys (including subkeys possibly used
to sign releases):

gpg --keyserver hkps://keys.openpgp.org --recv-keys 4ED778F539E3634C779C87C6D7062848A1AB005C
gpg --keyserver hkps://keys.openpgp.org --recv-keys 141F07595B7B3FFE74309A937405533BE57C7D57
gpg --keyserver hkps://keys.openpgp.org --recv-keys 74F12602B6F1C4E913FAA37AD3A89613643B6201
gpg --keyserver hkps://keys.openpgp.org --recv-keys 8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600
gpg --keyserver hkps://keys.openpgp.org --recv-keys C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8
gpg --keyserver hkps://keys.openpgp.org --recv-keys 890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4
gpg --keyserver hkps://keys.openpgp.org --recv-keys C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C
gpg --keyserver hkps://keys.openpgp.org --recv-keys 108F52B48DB57BB0CC439B2997B01419BD92F80A

See Verifying binaries for how to use these keys to
verify a downloaded file.

Security release stewards

When possible, the commitment to take slots in the
security release steward rotation is made by companies in order
to ensure individuals who act as security stewards have the
support and recognition from their employer to be able to
prioritize security releases. Security release stewards manage security
releases on a rotation basis as outlined in the
security release process.

License

Node.js is available under the
MIT license. Node.js also includes
external libraries that are available under a variety of licenses. See
LICENSE for the full
license text.

To the top