I've a Nodejs app and using Babel to enable ES6 features. I can run it on local system in dev mode. I want to deploy it to Kubernetes using PM2.
It is giving an error when I try to run it with PM2 using process.json.
/bin/bash:1
15:59:52 23|app | (function (exports, require, module, __filename, __dirname) { ����
15:59:52 23|app | ^
15:59:52 23|app | SyntaxError: Invalid or unexpected token
15:59:52 23|app | at new Script (vm.js:85:7)
15:59:52 23|app | at createScript (vm.js:266:10)
15:59:52 23|app | at Object.runInThisContext (vm.js:314:10)
15:59:52 23|app | at Module._compile (internal/modules/cjs/loader.js:698:28)
15:59:52 23|app | at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
15:59:52 23|app | at Module.load (internal/modules/cjs/loader.js:630:32)
15:59:52 23|app | at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
15:59:52 23|app | at Function.Module._load (internal/modules/cjs/loader.js:562:3)
This is my process.json
{
"apps": [
{
"name": "app",
"script": "./dist/bin/www.js --env production",
"exec_mode": "cluster",
"instances": 0,
"max_restarts": 20,
"env": {
"NODE_ENV": "production"
},
"env_production": {
"NODE_ENV": "production"
}
}
]
}
When I run this command pm2 ./dist/bin/www.js --env production
it works fine but when I try to run it using process.json like pm2 start process.json --no-daemon
it throws the above error.
I'm trying it on local system but it also happens when I deploy to gcloud using a Dockerfile with kubectl
Can someone point me to the right direction where I should try to look.
try this process.json:
{
"apps": [
{
"name": "app",
"script": "./dist/bin/www.js",
"exec_mode": "cluster",
"instances": 0,
"max_restarts": 20,
"env": {
"NODE_ENV": "development"
},
"env_production": {
"NODE_ENV": "production"
}
}
]
}
CLI:
pm2 start process.json --no-daemon --env production