Linux command
node 命令
网络
复制后可按需替换文件名、目录或参数。
常用示例
Run
node [script.js]
Start the REPL
node
Evaluate
node -e "[console.log('hello')]"
Pass arguments
node [script.js] [arg1] [arg2]
Run
node --inspect-brk [script.js]
Syntax-check
node --check [script.js]
Watch and restart
node --watch [script.js]
Run TypeScript
node --import [tsx] [script.ts]
Print version
node --version
说明
node is the Node.js JavaScript and (with `--experimental-wasi`) WebAssembly runtime built on the V8 engine. It executes scripts on the server, exposing an event-driven, non-blocking I/O model and a large standard library (`fs`, `http`, `crypto`, `stream`, `child_process`, etc.). Node supports both CommonJS (`require`) and ECMAScript modules (`import`). Module type is determined by the file extension (`.cjs`/`.mjs`) or by the nearest `package.json`'s `"type"` field. Built-in modules can be imported with the `node:` specifier (e.g. `import fs from 'node:fs/promises'`). The interpreter ships with npm and npx for package management, a built-in test runner (`node --test`), worker threads for CPU-bound parallelism, and a built-in debugger and profiler accessible through `--inspect`.
参数
- -e, --eval _CODE_
- Evaluate _code_ as JavaScript without loading a file.
- -p, --print _CODE_
- Like -e but prints the result to stdout.
- -r, --require _MODULE_
- Preload _module_ before running the main script (CommonJS only).
- --import _MODULE_
- Preload an ES module before running the main script.
- -c, --check
- Parse the script and check for syntax errors without executing it.
- -i, --interactive
- Force the REPL even if stdin is not a TTY.
- --inspect=_host:port_
- Enable the V8 inspector on the given host/port (default 127.0.0.1:9229).
- --inspect-brk=_host:port_
- Like --inspect but break before user code starts.
- --watch
- Restart the process when watched files change. (Node.js 18+)
- --watch-path _PATH_
- Additional path to watch when --watch is enabled.
- --enable-source-maps
- Use source maps for stack traces.
- --no-warnings
- Silence all process warnings (including deprecations).
- --max-old-space-size _MB_
- Set the V8 old-generation heap size in megabytes.
- --experimental-vm-modules
- Enable the experimental ES module API in the `vm` module.
- -v, --version
- Print Node.js version.
- -h, --help
- Print Node.js command-line help.
FAQ
What is the node command used for?
node is the Node.js JavaScript and (with `--experimental-wasi`) WebAssembly runtime built on the V8 engine. It executes scripts on the server, exposing an event-driven, non-blocking I/O model and a large standard library (`fs`, `http`, `crypto`, `stream`, `child_process`, etc.). Node supports both CommonJS (`require`) and ECMAScript modules (`import`). Module type is determined by the file extension (`.cjs`/`.mjs`) or by the nearest `package.json`'s `"type"` field. Built-in modules can be imported with the `node:` specifier (e.g. `import fs from 'node:fs/promises'`). The interpreter ships with npm and npx for package management, a built-in test runner (`node --test`), worker threads for CPU-bound parallelism, and a built-in debugger and profiler accessible through `--inspect`.
How do I run a basic node example?
Run `node [script.js]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -e, --eval _CODE_ do in node?
Evaluate _code_ as JavaScript without loading a file.