Node.js Runtime (macOS x64 Binary)

24.15.0 · active · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to execute a Node.js script using the specific `node` executable provided by the `node-darwin-x64` package, leveraging `npx` or direct path access.

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');
}

view raw JSON →