Running a recent Node version on DigitalOcean App platform
By Flavio Copes
Learn how to run a recent Node.js version on DigitalOcean App Platform by switching the buildpack to ubuntu-22 and setting the engines field in package.json.
To run a recent Node.js version on DigitalOcean App Platform you need two changes: switch the app’s buildpack stack to Ubuntu 22 in the App Spec, and declare the Node version in the engines field of package.json.
DigitalOcean App Platform apps by default currently (end 2023) run on Node 16.x, which is way too old for modern apps deployment. Many packages now require Node 18 or newer, so a fresh deploy can fail on dependencies alone.
Why is the default stuck on Node 16?
App Platform builds your app with a buildpack, and the buildpack runs on a stack, an Ubuntu image with a set of available runtimes. The default stack is old, and the Node versions it offers stop at 16.x.
The newer Ubuntu 22 stack has recent Node versions. So the trick is telling your app to build on that stack instead.
Switch the buildpack stack
You have to change the buildpack of the App in the App Spec. You can do it in the app dashboard settings, after you deployed it for the first time.
The App Spec is a YAML file that describes your whole app. Edit it and add this at the top level:
features:
- buildpack-stack=ubuntu-22
Saving the spec triggers a new deployment, so the change applies right away.
Set the Node version
Then you set the version in your package.json:
{
"engines": {
"node": "21.x"
}
}
The buildpack reads the engines field and installs that Node version during the build.
And for whatever reason, LTS versions were not supported on this setup, so asking for 20.x didn’t work for me. I used 21.x.
How do you know it worked?
Check the build logs of the next deployment. The buildpack prints the Node version it installs.
You can also log it from the app itself:
console.log(process.version) //v21.1.0
If you still get an old Node
The two changes go together. The engines field alone doesn’t help if the stack you’re building on doesn’t ship that Node version.
If the build log still shows Node 16, open the App Spec again and check the features section is actually there, at the top level of the YAML, with the exact buildpack-stack=ubuntu-22 value. A wrong indentation makes the setting silently disappear when you save.
Related posts about services: