Search code examples
node.jsnestjspm2node-mssql

Unable to run node application using pm2


I made a small nestjs webapp, it connects to a local mssql database and works fine... Except if I try to launch it using pm2.

  • regular yarn start:dev works (it translates to nest start --watch)
  • building the production and running yarn start:prod also works fine (it translates to node dist/main)
  • running nodemon build/main.js also works fine

But if I try to launch my app running pm2 start build/main.js I get DB connection errors: TypeError: The "config.server" property is required and must be of type string.

My DB connection parameters are currently stored in a .env file. I load them running env.config() and it's working fine for the other three running methods I listed. I've tried to change the parameters to include quotes and double quotes, with no luck:

  • db_host = localhost
  • db_host = 'localhost'
  • db_host = "localhost"

What am I doing wrong?


Solution

  • We just found out that changing the syntax from pm2 start to something like pm2 start npm --name "myApp" -- run start:prod worked.