PM2 Error: Cannot find module when using ecosystem file

Question

I'm having an issue with pm2.

If I start my app with

`cd /my/path
pm2 start server.js`

everything works correctly, but if I use an ecosystem.config.js file, then it gives the following error

`pm2 start ecosystem.config.js
Error: Cannot find module '/my/path/server.js'\n    at Function.Module._resolveFilename`

my ecosystem file is configured as follows

`module.exports = {
    "apps": [{
        "name": "MyApp",
        "script": "server.js",
        "cwd": "/my/path"
    }]
}`

I tried uninstalling pm2, updating npm and reinstalling node_modules, but still I can't understand why it says a module is missing in my file (expecially because it works when not using the ecosystem file)

Answer

Ensure that the ecosystem.config.js is in the root of your project as well as your server entry file (server.js) and specify your script as below:

`module.exports = {
    "apps": [{
        "name": "MyApp",
        "script": "./server.js"
    }]
}`

This answer was originally posted on Stack Overflow. You can find the full discussion here

Related Posts

Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?

## Question Can one transfer repositories from GitLab to GitHub if the need be. If so, how exactly can I go about doing the same? Also, are there any pitfalls in doing so or precautionary measures

Read More

Cannot set headers after they are sent to the client - error

## Question Error `[ERR_HTTP_HEADERS_SENT]`: Cannot set headers after they are sent to the client ```text `at ServerResponse.setHeader (_http_outgoing.js:558:11) at ServerResponse.header (D:\D

Read More

Pulling data with 'Where' and 'Include' statements at the same time

## Question I have managed to get my include statements working with my foreign keys however when I try to add a 'where' statement to the findAll statement I am getting the below error. I have check

Read More