Question

NodeJS API is not running

Today my API stopped working. No change was made in the code since August and it was working fine.

Runtime logs show this:

[api] [2024-10-28 14:32:11] Server running on port 3000
[api] [2024-10-28 14:33:37] undefined:1
[api] [2024-10-28 14:33:37] <html>
[api] [2024-10-28 14:33:37] ^
[api] [2024-10-28 14:33:37] 
[api] [2024-10-28 14:33:37] SyntaxError: Unexpected token '<', "<html>
[api] [2024-10-28 14:33:37] <h"... is not valid JSON
[api] [2024-10-28 14:33:37]     at JSON.parse (<anonymous>)
[api] [2024-10-28 14:33:37]     at Response.json (file:///workspace/node_modules/node-fetch/src/body.js:149:15)
[api] [2024-10-28 14:33:37]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[api] [2024-10-28 14:33:37] 
[api] [2024-10-28 14:33:37] Node.js v20.18.0

What could be the problem? Maybe some change in Digitalocean? Maybe the problem is the new Node v20?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
October 29, 2024

Hey Victor! 👋

Indeed, recently, DigitalOcean App Platform may have updated to Node v20, and it could be introducing some differences in how your API handles JSON parsing or external requests.

If your app is not compatible with Node v20, you can specify the Node version in your package.json file to ensure App Platform runs your app on a compatible version. Add this under engines:

"engines": {
  "node": "18.x" 
}

This would set it to Node 18.x, which is stable and avoids potential compatibility issues with Node 20.

Let me know how it goes!

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.