Node.js Runtime (macOS x64 Binary)
The `node-darwin-x64` package provides a pre-compiled Node.js runtime specifically for macOS (x64 architecture), currently at version 24.15.0. It enables developers to include a specific Node.js version directly within their project's dependencies, facilitating consistent environments for builds, tests, or embedded applications without relying on a system-wide Node.js installation. Node.js itself is an open-source, cross-platform JavaScript runtime environment that follows a predictable release cadence. New major versions are released every six months in April and October, which may introduce breaking changes. Even-numbered major versions are designated as Long Term Support (LTS) releases, offering 12 months of active support followed by 18 months of maintenance, focusing on stability and security.
Common errors
-
sh: node: command not found
cause The system's PATH environment variable does not include the `node_modules/.bin` directory, or you are not using a tool like `npx` that resolves local binaries.fixExecute your script using `npx node your-script.js` or specify the full path to the bundled Node.js executable: `node_modules/.bin/node your-script.js`. -
Error: Cannot find module 'some-module'
cause A required module (either built-in or third-party) cannot be found by the Node.js runtime. This could be due to a missing `npm install` for third-party modules or a typo in a built-in module name.fixFor third-party modules, ensure `npm install some-module` has been run. For built-in modules, verify the correct module name and use the `node:` prefix (e.g., `node:fs`). If using ESM, check `package.json` for `"type": "module"` and correct import paths.
Warnings
- breaking Node.js major versions, released every April and October, frequently introduce breaking changes. Projects relying on a specific Node.js version provided by this package should be prepared for potential incompatibilities when upgrading to a new major version.
- gotcha This package provides a `node` executable in `node_modules/.bin`. If a system-wide Node.js installation is also present, or if your PATH is configured differently, you might inadvertently use the wrong Node.js version. This can lead to inconsistent behavior or build failures.
- gotcha This package is a binary distribution and does not export any JavaScript modules directly. Attempts to `import` or `require` symbols directly from `'node-darwin-x64'` will result in errors.
- gotcha As a binary distribution, this package downloads pre-compiled Node.js executables. This introduces a supply chain dependency on the integrity of the original Node.js binaries and the `aredridel/node-bin-gen` repository.
Install
-
npm install node-darwin-x64 -
yarn add node-darwin-x64 -
pnpm add node-darwin-x64
Imports
- fs
import fs from 'fs';
import fs from 'node:fs';
- http
const http = require('http');import { createServer } from 'node:http'; - process
import { arch } from 'process';import process from 'node:process';
Quickstart
import { execSync } from 'node:child_process';
import { writeFileSync, unlinkSync } from 'node:fs';
import { join } from 'node:path';
// Create a simple script to demonstrate running Node.js
const scriptContent = `
console.log('Hello from Node.js (v' + process.version + ') provided by node-darwin-x64!');
console.log('Current architecture:', process.arch);
console.log('Current platform:', process.platform);
console.log('Environment variable GREETING:', process.env.GREETING ?? 'not set');
`;
const scriptFilePath = join(process.cwd(), 'hello-node.js');
writeFileSync(scriptFilePath, scriptContent);
console.log('Executing script using the Node.js runtime bundled by node-darwin-x64...');
try {
// Option 1: Using 'npx' (recommended for convenience)
// 'npx' automatically finds executables installed in node_modules/.bin
console.log('\n--- Running via npx ---');
const outputNpx = execSync('npx node hello-node.js', {
env: { ...process.env, GREETING: 'Hello from npx' },
encoding: 'utf8',
stdio: 'pipe' // Capture output
});
console.log(outputNpx);
// Option 2: Directly referencing the binary path
// Useful for explicit control or when 'npx' is not available
const nodeBinaryPath = join(process.cwd(), 'node_modules', '.bin', 'node');
console.log(`\n--- Running directly from ${nodeBinaryPath} ---`);
const outputDirect = execSync(`${nodeBinaryPath} hello-node.js`, {
env: { ...process.env, GREETING: 'Hello directly' },
encoding: 'utf8',
stdio: 'pipe' // Capture output
});
console.log(outputDirect);
} catch (error) {
console.error('Error running script:', error.message);
if (error.stderr) console.error('Stderr:', error.stderr);
} finally {
unlinkSync(scriptFilePath); // Clean up the temporary script
console.log('\nCleaned up temporary script: hello-node.js');
}