Email or username:

Password:

Forgot your password?
Stefan Judis

💡 TIL — the new `node --run` flag doesn't run life cycle scripts.

Node.js v23 was released last week and ships a new and stable `node --run` flag. The flag allows running `package.json` scripts without npm. It's slightly faster than `npm run` (we're talking a couple of hundred ms) but doesn't run life cycle scripts (e.g. `prestart`).

So `node --run` is not an `npm run` replacement.

Will you use it? I'd rather stick with `npm run` in this case... 🤔

Examples showing that `node --run` is slightly faster than `npm run` but also doesn't execute npm life cycle scripts.
9 comments
Mayank

@stefan i find automatically-called lifecycle scripts confusing anyway, so i prefer explicitly calling things. in this case, i'd prepend `node --run prestart &&` to the value of the `start` script.

Stefan Judis

@mayank That's fair. :)

I just think it's interesting to break compat here. I'm fine with either approach but having different behaviors will make me stay on `npm run` because I can't be bothered to think about lifecycle scripts. 🤷

Nicolas Hoizey

@stefan I think there's a typo in “So `npm --run` is not an `npm run` replacement”… 😅

Pascal Duez

@stefan For what it's worth, yarn removed lifecycle scripts support quite some time ago, pnpm support them but under a flag or config option.
Not trying to weigh against them actually, just pointing out that they did not reached consensus.

Stefan Judis

@pascalduez Very interesting. Thanks Pascal for this background info! 🙇

Thomas Hunter II

@stefan I like that it doesn't print all of the npm bs when an error occurs

Go Up