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