Skip to content

CLI & Build Commands

Fresh 🌱

Create a project

shell
npm init neon my-project          # scaffold a new Neon project
npm init neon@latest my-project   # use the latest generator

Produces:

text
my-project/
├── Cargo.toml      # Rust crate manifest
├── package.json    # npm package manifest
├── README.md
└── src/
    └── lib.rs      # your Neon code

Build

shell
npm install                  # installs deps and builds once
npm run build                # debug build  -> index.node (fast compile)
npm run build -- --release   # release build -> index.node (optimized)

Test from Node

shell
node
> const addon = require('.')
> addon.hello()
'hello node'

Clean

shell
cargo clean                  # remove the Rust target/ build directory

Verify the toolchain

shell
node --version
npm --version
rustc --version
cargo --version

Targeting a Node-API version

Set the napi feature in Cargo.toml (higher = more capabilities, newer minimum Node):

toml
[dependencies.neon]
features = ["napi-6"]

Add a Rust dependency

toml
# Cargo.toml
[dependencies]
num_cpus = "1"

Common artifacts

PathWhat it is
index.nodeThe compiled native module that require('.') loads.
target/Rust build output. Never publish this to npm.

Iterate on debug, ship on release

Debug builds compile quickly for a tight dev loop. Switch to --release when measuring performance or producing a published binary.