インストール
利用可能なモジュールリストを確認
# dnf module list nodejs
…
Red Hat Enterprise Linux 9 for x86_64 - AppStream (RPMs)
Name Stream Profiles Summary
nodejs 18 common [d], development, minimal, s2i Javascript runtime
nodejs 20 common [d], development, minimal, s2i Javascript runtime
nodejs 22 common [d], development, minimal, s2i Javascript runtime
利用するモジュールを有効化
※今回はv20を利用する
# dnf module enable nodejs:20
再度モジュールリストを確認
→v20がenableになっている
# dnf module list nodejs
…
Red Hat Enterprise Linux 9 for x86_64 - AppStream (RPMs)
Name Stream Profiles Summary
nodejs 18 common [d], development, minimal, s2i Javascript runtime
nodejs 20 [e] common [d], development, minimal, s2i Javascript runtime
nodejs 22 common [d], development, minimal, s2i Javascript runtime
ヒント: [d]efault, [e]nabled, [x]disabled, [i]nstalled
モジュールをインストール
# dnf install nodejs
…
==============================================================================================================
パッケージ Arch バージョン リポジトリー サイズ
==============================================================================================================
インストール:
nodejs x86_64 1:20.18.2-1.module+el9.5.0+22758+4ad2c198 rhel-9-for-x86_64-appstream-rpms 14 M
弱い依存関係のインストール:
nodejs-docs noarch 1:20.18.2-1.module+el9.5.0+22758+4ad2c198 rhel-9-for-x86_64-appstream-rpms 8.5 M
nodejs-full-i18n
x86_64 1:20.18.2-1.module+el9.5.0+22758+4ad2c198 rhel-9-for-x86_64-appstream-rpms 8.4 M
npm x86_64 1:10.8.2-1.20.18.2.1.module+el9.5.0+22758+4ad2c198 rhel-9-for-x86_64-appstream-rpms 2.3 M
トランザクションの概要
==============================================================================================================
インストール 4 パッケージ
…
バージョン確認
# node -v
v20.18.2
動作確認
テスト用プログラムの作成
# vi hello-heep.js
const http = require('node:http');
const hostname = process.argv[2] || '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}/`);
});
ファイアウォールを開ける
# firewall-cmd --add-port=3000/tcp
# firewall-cmd --add-port=3000/tcp --permanent
プログラム起動
# node hello-http.js 10.2.153.95
Server running at http://10.2.153.95:3000/
ブラウザで接続