PM2 cluster mode nodeJS - pm2

PM2: v.4.4.0
NodeJS: v.10.16.0.
config.json:
{
"name": "app-name",
"script": "server",
"exec_mode": "fork",
"instances": 0,
"wait_ready": true
"listen_timeout": 10000,
"kill_timeout": 5000,
<config params>....
}
I try to start app in Windows 2012 Server and Ubuntu 18.
If i start in fork all works.
│ 28 │ front-qa │ default │ N/A │ fork │ 10216 │ 22m │ 0 │ online │ 0% │ 232.4mb │
mku: │ disabled │
└─────┴─────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴
But if I try to start pm2 start app config.json with cluster mode - don't work.
config.json:
{
"name": "app-name",
"script": "server",
"exec_mode": "cluster",
"instances": 0,
"wait_ready": true
"listen_timeout": 10000,
"kill_timeout": 5000,
<config params>....
}
In windows:
C:\PROGRAM FILES\NODEJS\NODE.EXE:1
MZ�
^
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:721:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at C:\Tools\npm\node_modules\pm2\lib\ProcessContainer.js:303:25
at wrapper (C:\Tools\npm\node_modules\pm2\node_modules\async\internal\once.js:12:16)
at next (C:\Tools\npm\node_modules\pm2\node_modules\async\waterfall.js:96:20)
at C:\Tools\npm\node_modules\pm2\node_modules\async\internal\onlyOnce.js:12:16
at WriteStream.<anonymous> (C:\Tools\npm\node_modules\pm2\lib\Utility.js:186:13)
in Ubuntu 18 with NVM:
/opt/nvm/nvm/versions/node/v10.16.0/bin/node:1
.ELF....
^
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:721:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at /opt/nvm/nvm/versions/node/v10.16.0/lib/node_modules/pm2/lib/ProcessContainer.js:303:25
at wrapper (/opt/nvm/nvm/versions/node/v10.16.0/lib/node_modules/pm2/node_modules/async/internal/once.js:12:16)
at next (/opt/nvm/nvm/versions/node/v10.16.0/lib/node_modules/pm2/node_modules/async/waterfall.js:96:20)
at /opt/nvm/nvm/versions/node/v10.16.0/lib/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
at WriteStream.<anonymous> (/opt/nvm/nvm/versions/node/v10.16.0/lib/node_modules/pm2/lib/Utility.js:186:13)
Any body help?

Related

PhpStorm error when running debugger: SyntaxError: Unexpected token = (on class property)

static UNUSED_TILE = " ";
^
SyntaxError: Unexpected token =
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Waiting for the debugger to disconnect...
When I comment out that specific static property, it errs on the next one in the file:
class Tile {
static UNUSED_TILE = " ";
static HUMAN_MARKER = "X";
static COMPUTER_MARKER = "O";
I have Node 12.4.0. This only happens when running my debugger in PhpStorm 2019.3. node fileName.js in terminal runs without issues. Any idea what the the debugger could be doing to still have issue?
//package.json
"babel": {
"presets": [
"#babel/preset-env"
],
"plugins": [
"#babel/plugin-proposal-class-properties",
"babel-plugin-transform-class-properties"
]
},
"devDependencies": {
"#babel/plugin-proposal-class-properties": "^7.8.3",
"#babel/preset-env": "^7.9.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"eslint": "^6.8.0",
"jest": "^25.2.3",
"jest-cli": "^25.2.3"
}
Debugger settings
Your screenshots show that you have node 8.10.0 used as node.js interpreter; this node.js version doesn't support class properties. According to this table, they are supported since Node.js 12.x. If you have the appropriate version installed (you wrote that you have Node 12.4.0), please make sure to select it as a Node interpreter: in your run configuration

Unexpected token with valid json?

Why can't I print this simple json? jsonlint.com says this is valid
json:
[
   {
      "token_start_offset": "0.00",
      "token_duration": "4.00",
      "token_base_start_offset": "0.00",
      "token_base_duration": "4.00",
      "token_type": "background_noise",
      "token_background_noise_type": "other",
      "session_id": "1459194633575",
      "token_base_form": "…",
      "token_print_form": "…",
      "session_boundary": "begin",
      "nonspeech_boundary": "begin",
      "token_id": "0"
   }
]
app.js:
var testJson = require('./json');
console.log(testJson);
But when I run this, I get the below error:
Error:
module.js:428
throw err;
^
SyntaxError: C:\Users\Owner\Desktop\format test\json.json: Unexpected token  
at Object.parse (native)
at Object.Module._extensions..json (module.js:425:27)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Users\Owner\Desktop\format test\app.js:1:78)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
Windows 10
node -v 4.2.6
Because the JSON parser in Node's require() assumes ASCII characters and your example contains a Unicode character: …. If you replace all instances of … with \u2026, your JSON should parse.

pm2 doesn't work with config json however works with direct command

I am using pm2 to manage my node js server. Strangly when I use pm2.config.json file then it doesn't recognize the relative paths and node js server fails to load the file and try to kill node js process and when pm2 see node process is kills then it try to restart node and went to infinite loop. Following are details.
pm2.config.json
{
"apps": [
{
"name": "Application",
"script": "./server.js",
"watch": false
}
]
}
Command to start pm2:
pm2 start dist/BHS/pm2.config.json
Error thrown:
BHS Application-0 (err): at Module._compile (module.js:456:26)
BHS Application-0 (err): at Object.Module._extensions..js (module.js:474:10)
BHS Application-0 (err): at Module.load (module.js:356:32)
BHS Application-0 (err): at Function.Module._load (module.js:312:12)
BHS Application-0 (err): at Function.Module.runMain (module.js:497:10)
BHS Application-0 (err):
BHS Application-0 (err): module.js:340
BHS Application-0 (err): throw err;
BHS Application-0 (err): ^
BHS Application-0 (err): Error: Cannot find module './server/config/DBConfig.js'
BHS Application-0 (err): at Function.Module._resolveFilename (module.js:338:15)
BHS Application-0 (err): at Function.Module._load (module.js:280:25)
BHS Application-0 (err): at Module.require (module.js:364:17)
BHS Application-0 (err): at require (module.js:380:17)
BHS Application-0 (err): at Object.<anonymous> (/Users/dilipkumar/Dilip/Projects/BHS/SourceCode/BHS/server.js:19:16)
BHS Application-0 (err): at Module._compile (module.js:456:26)
BHS Application-0 (err): at Object.Module._extensions..js (module.js:474:10)
BHS Application-0 (err): at Module.load (module.js:356:32)
BHS Application-0 (err): at Function.Module._load (module.js:312:12)
BHS Application-0 (err): at Function.Module.runMain (module.js:497:10)
However same works wihtout pm2.config.json
pm2 start --watch dist/BHS/server.js
Please help.
According to PM2 docs, pm2 starts modules (applications) from where it is launched.
So best option would be to use absolute paths.
However, if you want to launch them through relative paths, then use 'cwd' option:
{
"name": "Application",
"script": "./server.js",
"cwd": "/srv/node-app/dist/BHS"
}
PM2 should also support paths relative to user's homedir (~/path), if you want something more flexible than absolute paths but more reliable than 'fully' relative ones.

dlopen being called on OS X on Node v0.11 (couchnode 1.2.4)

I used code below to test couchbase
var couchbase = require('couchbase');
var db = new couchbase.Connection({
bucket: "default"
},
function(err) {
if (err) throw err;
db.set('testdoc1', {
name: 'Frank1'
}, function(err, result) {
if (err) throw err;
db.get('testdoc1', function(err, result) {
if (err) throw err;
console.log(result.value);
// {name: Frank}
});
});
});
but it reports
/Users/mymac/node_modules/couchbase/lib/binding.js:17
throw e;
^
Error: dlopen(/Users/mymac/node_modules/couchbase/prebuilt/win/x64/couchbase_impl.node, 1): no suitable image found. Did find:
/Users/mymac/node_modules/couchbase/prebuilt/win/x64/couchbase_impl.node: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at bindings (/Users/mymac/node_modules/couchbase/node_modules/bindings/bindings.js:74:15)
at tryLoadBinding (/Users/mymac/node_modules/couchbase/lib/binding.js:13:31)
at Object.<anonymous> (/Users/mymacg/node_modules/couchbase/lib/binding.js:31:17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
your comment welcome
0x4d 0x5a is the file signature of a Windows executable, in other words your couchbase node client install is not for Mac, it's for Windows.
This also seems to be what the path is saying;
prebuilt/win/x64
This problem may be caused by the node_modules dir being checked into source control on a windows machine and checked out on a mac instead of using package.json to do a local install.
I was able to resolve this is on OS X 10.9.5 with xcode 6.0.1
Install a fresh copy of libcouchbase:
$ brew install libcouchbase
This will install libcouchbase into /usr/local/Cellar/libcouchbase/2.4.1 (or whatever version is current).
Next install Node-SDK via npm
$ npm install --couchbase-root=/usr/local/Cellar/libcouchbase/2.4.1 couchbase
/Users/csun/dev/projects/cashier-api/cashier-api-site/node_modules/couchbase/lib/binding.js:17
throw e;
^
Error: dlopen(/Users/csun/dev/projects/cashier-api/cashier-api-site/node_modules/couchbase/prebuilt/win/x64/couchbase_impl.node, 1): no suitable image found. Did find:
/Users/csun/dev/projects/cashier-api/cashier-api-site/node_modules/couchbase/prebuilt/win/x64/couchbase_impl.node: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
at Error (native)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at bindings (/Users/csun/dev/projects/cashier-api/cashier-api-site/node_modules/couchbase/node_modules/bindings/bindings.js:74:15)
at tryLoadBinding (/Users/csun/dev/projects/cashier-api/cashier-api-site/node_modules/couchbase/lib/binding.js:13:31)
at Object.<anonymous> (/Users/csun/dev/projects/cashier-api/cashier-api-site/node_modules/couchbase/lib/binding.js:31:17)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
I got the same situation, solved by using node 0.10 instead of 0.12 in my project. Which means your issue could be solved by change node version or couchbase version.
my couchbase version is
├─┬ couchbase#1.2.4
│ ├── bindings#1.0.0

node.js fnoc module gives error -- probably something simple

I'm sure I'm doing something stupid, but I can't get node-fnoc to work. I have a directory with a simple package.json in it, I have a /config/ directory in that directory with a simple JSON file in it. And, I'm basically just trying to do what they have in their example.
var fnoc = require('fnoc');
fnoc(function(err, configs){
console.log(configs);
});
and this is what I'm getting:
fnoc(function(err, configs){
^
TypeError: object is not a function
at Object.<anonymous> (/opt/backups/readconfig.js:3:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
Any ideas?
The document on github is for version 0.2.2
You need to install fnoc#0.2.2
npm install fnoc#0.2.2
Run your js
node your.js
Output:
{ package:
{ name: 'asdf',
dependencies:
{ express: '*',
jade: '*',
Version is in the changelog file:
https://github.com/jprichardson/node-fnoc/blob/master/CHANGELOG.md