コンテンツにスキップ
Wikipedia

Node.js

出典: フリー百科事典『ウィキペディア(Wikipedia)』
Node.js
Node.js
作者 ライアン・ダール
開発元 Node.js Developers
初版 2009年 (16年前) (2009)
最新版
25.0.0[1]  ウィキデータを編集 / 2025年10月15日 (6日前)
リポジトリ ウィキデータを編集
プログラミング
言語
C++, JavaScript
対応OS macOS, Linux, Solaris, FreeBSD, OpenBSD, Windows, webOS
プラットフォーム x86, x64, ARM, Power, z/Architecture
種別 イベント駆動型
ライセンス MIT License
公式サイト nodejs.org
テンプレートを表示

Node.js(ノード・ジェイエス) はV8 JavaScriptエンジン上に構築されたJavaScript実行環境の1つである[2] イベント化された入出力を扱うサーバサイド JavaScript環境であり、Webサーバなどのスケーラブルネットワーク プログラムの記述を意図している[3] ライアン・ダールによって2009年に作成され、ダールを雇用しているJoyentの支援により成長している[4] [5]

概要

[編集 ]

V8 JavaScriptエンジンで動作するが、ChakraCoreバージョンやMozillaによるSpiderMonkey移植のプロジェクトも存在する。

Node.jsはPythonTwistedPerlPerl Object Environment (英語版)C言語libevent (英語版)RubyEventMachine (英語版)と同様の目的を持つ。 ほとんどのJavaScriptとは異なり、ウェブブラウザの中で実行されるのではなく、むしろサーバサイドJavaScriptの一種である。 Node.jsはいくつかのCommonJS仕様を実装している[6] 。 Node.jsは対話的なテスト用にREPL (Read-eval-print loop) 環境を含んでいる。

Node.jsを用いた構成としてはMEAN等が提唱されている。

[編集 ]

Node.jsによるHTTPサーバ版のHello world:

consthttp=require('http');
http.createServer(function(request,response){
response.writeHead(200,{'Content-Type':'text/plain'});
response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://127.0.0.1:3000/');

3000番ポートで接続を待ち受けて、受け取ったデータをエコーバックする単純なTCPサーバ:

constnet=require('net');
constserver=net.createServer(function(stream){
stream.write('hello\r\n');
stream.on('data',function(data){
stream.write(data);
});
stream.on('end',function(){
stream.end('goodbye\r\n');
});
});
server.listen(3000,'localhost');

モジュール

[編集 ]

Node.jsは、バイナリコンパイルされた多くの「コア・モジュール」とともに提供される。それはネットワークの非同期ラッパーであるnetモジュールの他、パスやファイルシステムバッファタイマー、より一般的なストリームなどの基本的なモジュールを含む。サードパーティー製のモジュールを使用することも可能である。それはプリコンパイルされた ".node" アドオン、または、プレーンなJavaScriptファイルのどちらの形式でもよい。JavaScriptモジュールはCommonJSモジュール仕様[7] に従って実装され、モジュールが実装する関数や変数へのアクセスにはexports変数が使われる[8]

サードパーティーのモジュールはNode.jsを拡張または抽象レベルを提供することで、ウェブアプリケーションで使われる様々なミドルウェア実装することができる。たとえばポピュラーなフレームワークとしてconnectおよびExpress.jsがある。モジュールは単なるファイルとしてインストールすることもできるが、通常はnpmを使ってインストールされる。それは依存性の扱いも含めてモジュールの構築、インストール、更新を助けてくれる。さらに、モジュールはNodeのデフォルトであるモジュール用ディレクトリにインストールしなくても、相対的なパス名を要求することで見つけられる。Node.js wikiに利用可能なサードパーティー製のモジュール一覧がある。

Node.jsを用いたWebアプリケーションでは、Express.jsEmber.js (英語版)Matador (英語版)のようなフレームワークを用いて開発を行うことが多い。

表明

[編集 ]

Node.jsはコアモジュール assert により表明(assertion)に対応している。表明違反時にはassert.AssertionError インスタンスがスローされる[9]

constassert=require('assert').strict;
assert.deepEqual(1,2);
// Thrown:
// AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
// 
// 1 !== 2

ECMAScript modules

[編集 ]

Node.jsは ECMAScript modules (ES module) に対応しており[10] 、以下のいずれかを満たすものをES moduleとしてロードする[11]

  • 拡張子が .mjs であるファイル
  • 拡張子が .js かつ最近傍の親 package.json"type":"module" が指定されたファイル
  • --input-type=module フラグと共に引数として渡されたモジュール文字列

リリース

[編集 ]

Node.jsは長期サポート (LTS) リリースモデルを採用している。

各メジャーバージョンはPendingCurrent → (Active LTSMaintenance LTS →) End of Life のリリース状態を経る。Currentリリースは6ヶ月間続き、奇数バージョンはその後Maintenance LTSのみを経てサポートが終了し、偶数バージョンはActive LTSを経てMaintenance LTSへ移行する。プロダクションアプリケーションは Active LTS あるいは Maintenance LTS のいずれかのみを利用しなければならない[12]

Release Status Code name Release date Active LTS start Maintenance start Maintenance end
サポート終了:v0.10.x サポート終了:End-of-Life 2013年03月11日 - 2015年10月01日 2016年10月31日
サポート終了:v0.12.x サポート終了:End-of-Life 2015年02月06日 - 2016年04月01日 2016年12月31日
サポート終了:4.x サポート終了:End-of-Life Argon 2015年09月08日 2015年10月01日 2017年04月01日 2018年04月30日
サポート終了:5.x サポート終了:End-of-Life 2015年10月29日 N/A 2016年06月30日
サポート終了:6.x サポート終了:End-of-Life Boron 2016年04月26日 2016年10月18日 2018年04月30日 2019年04月30日
サポート終了:7.x サポート終了:End-of-Life 2016年10月25日 N/A 2017年06月30日
サポート終了:8.x サポート終了:End-of-Life Carbon 2017年05月30日 2017年10月31日 2019年01月01日[13] 2019年12月31日
サポート終了:9.x サポート終了:End-of-Life 2017年10月01日 N/A 2018年06月30日
サポート終了:10.x サポート終了:End-of-Life Dubnium 2018年04月24日 2018年10月30日 2020年05月19日 2021年04月01日
サポート終了:11.x サポート終了:End-of-Life 2018年10月23日 N/A 2019年05月01日 2019年06月01日
サポート終了:12.x サポート終了:End-of-Life Erbium 2019年04月23日 2019年10月21日 2020年11月30日 2022年04月30日
サポート終了:13.x サポート終了:End-of-Life 2019年10月22日 N/A 2020年04月01日 2020年06月01日
サポート終了:14.x サポート終了:End-of-Life Fermium 2020年04月21日 2020年10月27日 2021年10月19日 2023年04月30日
サポート終了:15.x サポート終了:End-of-Life 2020年10月20日 N/A 2021年04月01日 2021年06月01日
サポート終了:16.x サポート終了:End-of-Life Gallium 2021年04月20日 2021年10月26日 2022年10月18日 2023年09月11日[14]
サポート終了:17.x サポート終了:End-of-Life 2021年10月19日 N/A 2022年04月01日 2022年06月01日
サポート終了:18.x サポート終了:End-of-Life Hydrogen 2022年04月19日 2022年10月25日 2023年10月18日 2025年04月30日
サポート終了:19.x サポート終了:End-of-Life 2022年10月18日 N/A 2023年04月01日 2023年06月01日
サポート中:20.x サポート中:Maintenance Iron 2023年04月18日 2023年10月24日 2024年10月22日 2026年04月30日
サポート終了:21.x サポート終了:End-of-Life 2023年10月17日 N/A 2024年04月01日 2024年06月01日
サポート中:22.x サポート中:Active LTS Jod 2024年04月24日 2024年10月29日 2025年10月21日 2027年04月30日
サポート終了:23.x サポート終了:End-of-Life 2024年10月16日 N/A 2025年04月01日 2025年06月01日
現行バージョン:24.x 現行バージョン:Current 2025年05月06日 2025年10月28日 2026年10月20日 2028年04月30日
凡例
サポート終了
サポート中
現行バージョン
最新プレビュー版
将来のリリース

コミュニティ

[編集 ]

主に2つのメーリングリスト nodejsnodejs-dev 、そして freenode上の IRC チャンネル #node.js を中心とするとても活発な開発者コミュニティが存在する。コミュニティはNode.jsにフォーカスした開発者会議であるNodeConfに集結する[15]

Windows版

[編集 ]

0.5.1より、Windowsネイティブ版バイナリをリリースをした[16] 。Windowsネイティブ版リリースに関してはマイクロソフトの支援が行われた。Windows向けの非同期I/O環境(Input/output completion port (英語版)、以下IOCP)に対応するため、libuv[17] を作成することにより抽象化を進めた。結果としてlibev、libeioが使えるUnix系プラットフォームとIOCPを利用するWindowsプラットフォーム向けのリリースが可能になった。

クライアント1万台問題

[編集 ]

非同期処理のNode.jsではクライアント1万台問題は起きない[18]

Node.jsでこの問題を解決した技術の中核は、シングルスレッドにおける非同期処理を容易に実装可能にしたイベント駆動型プログラミング環境である。

Docker Image

[編集 ]

Node.js公式からDocker イメージが配布されている[19] 。イメージは以下の3種類に大別され、全てのイメージでnode/npm/yarnがプリインストールされている[20]

  • node:<version>: デファクトスタンダード[21] 。Docker公式のbuildpack-depsを基に構築[22]
  • node:alpine: Alpine Linuxベース[23] 。イメージサイズを最小化したい際に推奨される[24]
  • node:slim: Node.js動作に必要最低限のパッケージのみを含む[25] 。サイズに制限がない限りデファクトイメージの利用を強く推奨[26]

デフォルト以外の設定(例: npmアップグレード)を利用する手引き「Docker and Node.js Best Practices」や GetStarted が公式から提供されている。

脚注・出典

[編集 ]
  1. ^ "Release 25.0.0"; 閲覧日: 2025年10月20日; 出版日: 2025年10月15日.
  2. ^ Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js
  3. ^ http://www.readwriteweb.com/hack/2011/01/wait-whats-nodejs-good-for-aga.php
  4. ^ http://mashable.com/2011/03/10/node-js/
  5. ^ Alex Handy (2011年6月24日). "Node.js pushes JavaScript to the server-side". SDTimes. 2011年6月24日閲覧。
  6. ^ http://wiki.commonjs.org/wiki/Implementations/node.js
  7. ^ "CommonJS Implementations". 2011年5月15日閲覧。
  8. ^ Ryswyck, Jan. "Taking Baby Steps with Node.js – CommonJS and Creating Custom Modules". 2011年5月15日閲覧。
  9. ^ All errors thrown by the assert module will be instances of the AssertionError class. Node.js
  10. ^ "Node.js fully supports ECMAScript modules" Modules: ECMAScript modules . Node.js v16.19.1 documentation. 2023年02月19日閲覧.
  11. ^ "Node.js will treat the following as ES modules ... Files with an .mjs extension ... Files with a .js extension when the nearest parent package.json file contains a top-level "type" field with a value of "module". ... as an argument ... with the flag --input-type=module." Modules: Packages . Node.js v16.19.1 documentation. 2023年02月19日閲覧.
  12. ^ Production applications should only use Active LTS or Maintenance LTS releases. Node.js
  13. ^ "Node 8 reschedule". 2019年1月22日閲覧。
  14. ^ "Bringing forward the End-of-Life Date for Node.js 16". 2023年2月15日閲覧。
  15. ^ http://www.readwriteweb.com/hack/2011/04/nodeconf-schedule-announced.php
  16. ^ http://blog.nodejs.org/2011/07/14/node-v0-5-1/
  17. ^ https://github.com/joyent/libuv
  18. ^ 福田崇男 (2012年7月31日). "スタバ方式で「C10K問題」を解消". 日経コンピュータ. 日経BP社. 2017年2月20日閲覧。
  19. ^ The official Node.js docker image, made with love by the node community. [1]
  20. ^ All of the images contain pre-installed versions of node, npm, and yarn. [2]
  21. ^ This is the defacto image. [3]
  22. ^ This tag is based off of buildpack-deps. [4]
  23. ^ This image is based on the popular Alpine Linux project, available in the alpine official image. [5]
  24. ^ This variant is highly recommended when final image size being as small as possible is desired. [6]
  25. ^ This image does not contain the common packages contained in the default tag and only contains the minimal packages needed to run node. [7]
  26. ^ Unless you are working in an environment where only the Node.js image will be deployed and you have space constraints, we highly recommend using the default image of this repository. [8]

関連項目

[編集 ]
ウィキメディア・コモンズには、Node.js に関連するカテゴリがあります。

外部リンク

[編集 ]
概念
エンジン
コンパイラ
デバッガ
エディタ
サーバーサイド
フレームワークライブラリ
ユニットテスト
Docジェネレータ
コード解析
パッケージ管理
アプリケーションバンドラー
関連技術
人物

AltStyle によって変換されたページ (->オリジナル) /