s2i-nodejs-container
s2i-nodejs-container copied to clipboard
alternatives to npm start
I've noticed that the resulting s2i image starts the Node.js application using npm start.
This is a good idea since it's common practice and enables a developer to set flags etc, but it does result in two Node.js processes being launched, as seen in this screenshot:
We have the npm
process, and then the child node
process.
The npm
process is mostly idle, but does consume memory and adds overhead on startup.

Is it worth giving consideration to support a new environment variable that defines a shell script to use on startup instead?
This doesn't entirely address the issue, but you should be able to run any script that is defined in your package.json
using the NPM_RUN
env var.
Last I checked, I think we actually run something like: npm run $NPM_RUN
with a default setting of "NPM_RUN=start". I prefer this to DEV_MODE, because restarting everything via nodemon isn't really ideal for inner-loop work.
see https://github.com/sclorg/s2i-nodejs-container/blob/master/14/s2i/bin/run#L20-L26
@ryanj I think maybe I need to explain this better. The issue isn't the target script, the issue is overhead of using npm run
, since it creates two Node.js processes inside the container. Running node index.js
would create just one process.
It's minor, but if someone were to run an image built this way for a serverless/knative application then the 9x increased startup time (see second screenshot) could start to matter.
Edit: Spelling
Fyi - some info/discussion on this topic is provided in the Node.js Reference architecture: https://github.com/nodeshift/nodejs-reference-architecture/blob/main/docs/development/building-good-containers.md#avoiding-using-npm-to-start-application. It would be good to have a way to run without having to use npm.