Node.js Developer interview question

How do you deploy a Node.js service safely?

Build an immutable artifact, run checks and migrations compatibly, deploy progressively, expose readiness, stop accepting traffic before shutdown, drain in-flight requests, monitor errors and latency, and keep rollback tested.

Direct answer

What a strong answer covers

How it works

The build produces one immutable image with dependencies installed from the lockfile and a pinned Node version. CI runs tests and any migration in its expand phase before the rollout. The rollout is progressive: new instances start, report ready only after they can serve, receive traffic, and old instances get SIGTERM, stop accepting connections, finish in-flight requests within a timeout, and exit. Error rate and latency are watched during the rollout and the previous image is redeployable in one command. Configuration comes from the environment so the same image runs in every stage.

Example

A Kubernetes Deployment runs the image with a readiness probe on /ready that checks the database connection, a preStop hook that sleeps a few seconds so the load balancer stops routing, and a handler for SIGTERM that calls server.close and waits up to 20 s for in-flight requests. A rollout that pushed error rate above 1 percent was rolled back automatically by the progressive delivery controller.

Common mistakes

  • Running npm install at container start and getting a different dependency tree in production.
  • Exiting immediately on SIGTERM and cutting off active requests.
  • Reporting ready before the database pool is connected and serving 500s for the first seconds.

A useful answer structure

Answer from your own work.

Do not memorise a script: use only examples you can explain honestly in follow-up questions.

Practise this answer with MiraHint

Open the desktop workspace and rehearse a clear answer in your own words.

Download MiraHint
Node.js Developer interview questions