Solvedpm2 How do you run a TypeScript app with ts-node parameters?

I normally run my app with the following command on a test server:

ts-node --type-check -r tsconfig-paths/register src/server.ts

Now I want to use pm2 to go into production, but when I run:

pm2 start src/server.ts

It errors out because it can't find the paths properly, because the tsconfig-paths is not loaded.

How can I configure pm2 to run ts-node with those parameters?

23 Answers

✔️Accepted Answer

I am using pm2 start ts-node -- -P tsconfig.server.json ./server/index.ts

Other Answers:

incidentally for those using ecosystem:

    "script": "ts-node", // or locally "./node_modules/.bin/_ts-node" 
    "args": "src/main.ts"

How about trying pm2 start ts-node -- --type-check -r tsconfig-paths/register src/server.ts?

Pm2 is able to launch a normal bin (or says, a command) with arguments (--type-check -r tsconfig-paths/register src/server.ts) after the first -- feeding to your bin (i.e. in this case, ts-node).

It's very simple guys.

Just use tsc and pm2 watch combination with single & to run both commands.

"scripts": {
    "serve": "tsc src/app.ts -w & pm2 start dist/app.js --watch"

More Issues: