Deploy failed for Node Express backend in monorepo

I’m new to deploying web services on Render and i’m trying to deploy the backend part of my monorepo as a web service. The backend is Node Express, and it seems to build successfully, but then the project won’t start, and throws the error:

Error: Cannot find module ‘/opt/render/project/src/backend/server.js’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
at Function.Module._load (internal/modules/cjs/loader.js:730:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) at internal/main/run_main_module.js:17:47 { code: ‘MODULE_NOT_FOUND’,

I’m confused about the path in the error, and this may be a stupid question, but what is the src in the "‘/opt/render/project/src/backend/server.js’, is it just something Render inserts for all paths, or do i need to add one in?

I’ve tried all sorts of root directory paths: ./backend, ./backend/server

It doesn’t seem to match the one in my filesystem (see picture). My frontend static site deployed just fine.

/opt/render/project/src is the “home directory” where your repository’s sources are placed. Based off that screenshot you should be calling node server/server.js to start your application.

Unrelated aside: .env should NEVER be committed to git. I don’t recognize the IDE you’re using, most I’ve seen usually have ignored or uncommitted files in a different color, style, etc. Committing .env to git runs the risk of exposing passwords and any/all sensitive data. Don’t commit .env to git.

Hi Jason, thanks that worked a charm. Thanks for pointing out about the .env also

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.