本文へ移動
章と記事の一覧

動かす実行環境

Containers で Node.js を動かす

isolate では動かない child_process や、本物のファイルシステム・OS の情報が、コンテナでは普通に使える

エディタへ移動

import { execSync } from "node:child_process";
import { readdirSync, writeFileSync } from "node:fs";
import os from "node:os";

// isolate では使えない child_process と、実ファイルシステムが使える / child_process and a real file system work here
console.log("node", process.version, os.platform(), os.arch());
writeFileSync("/tmp/hello.txt", "hello from container");
console.log("/tmp has hello.txt:", readdirSync("/tmp").includes("hello.txt"));
console.log("uname:", execSync("uname -sr").toString().trim());

実行結果

実行するとここに結果が出ます。ネットワークは塞がれています。