nodemon issue with debug package in nodejs - node.js

I am trying to dubug my app using debug package through nodemon package and I am facing this much trouble that my required output is hidden inside the messy irrelevant information as you can see
Error / Issue
[nodemon] restarting due to changes...
nodemon bus emit: restart +25s
nodemon bus new listener: start (0) +0ms
nodemon bus new listener: start (0) +1ms
[nodemon] starting `node ./build/index.js`
nodemon fork C:\Windows\system32\cmd.exe /d /s /c node ./build/index.js +25s
nodemon bus emit: start +5ms
nodemon bus new listener: exit (2) +1ms
nodemon start watch on: *.* +2ms
[nodemon] restarting due to changes...
nodemon bus emit: restart +4ms
nodemon bus.emit(exit) via SIGUSR2 +218ms
nodemon bus emit: exit +215ms
[nodemon] starting `node ./build/index.js`
nodemon fork C:\Windows\system32\cmd.exe /d /s /c node ./build/index.js +5ms
nodemon bus emit: start +5ms
nodemon bus new listener: exit (1) +1ms
nodemon start watch on: *.* +2ms
app:normal it is normal debugger... +0ms
Listening on port: 3000
^CTerminate batch job (Y/N)? y
E:\Web Apps\RESTful API\express-demo>nodemon ./build/index.js
nodemon bus new listener: reset (0) +0ms
nodemon bus new listener: reset (0) +3ms
nodemon bus new listener: quit (0) +26ms
nodemon bus new listener: quit (0) +0ms
nodemon bus new listener: restart (0) +1ms
nodemon bus new listener: restart (0) +0ms
nodemon bus new listener: reset (2) +6ms
nodemon bus emit: reset +1ms
nodemon resetting watchers +0ms
nodemon reset +0ms
nodemon config: dirs [ 'E:\\Web Apps\\RESTful API\\express-demo' ] +0ms
[nodemon] 1.17.3
[nodemon] to restart at any time, enter `rs`
nodemon bus new listener: error (0) +106ms
nodemon bus new listener: error (0) +0ms
[nodemon] watching: *.*
[nodemon] starting `node ./build/index.js`
nodemon fork C:\Windows\system32\cmd.exe /d /s /c node ./build/index.js +0ms
nodemon bus new listener: exit (0) +12ms
nodemon bus new listener: exit (0) +1ms
nodemon start watch on: *.* +3ms
nodemon start watch on: E:\Web Apps\RESTful API\express-demo +119ms
nodemon ignored [ '**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**',
re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/ ] +1ms
nodemon watch is complete +147ms
app:normal it is normal debugger... +0ms
Listening on port: 3000
I am following these commands to debug my app
Inside index.js
const debug = require('debug')('app:start')
debug('debugging the app... Yup!')
Inside Terminal
set DEBUG=app:start // inside terminal
nodemon index.js // inside terminal

Issue was very silly that I was running these two commands in different terminals that cause the problem
set DEBUG=app:start // inside terminal
nodemon index.js // inside terminal
be sure to run these commands in the same terminal.
Hope this will save time for someone.

Related

Run NodeJS server from AWS EC2

EC2 is properly deployed with my NodeJS server but I can't figure out how to keep it running without an ssh connection to the linux machine and running npm start
For Example:
[ec2-user#ip-172-31-89-105 me_server]$ npm start
> me-server#1.0.0 start
> nodemon index.js
[nodemon] 2.0.20
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
Server Started at 8080
Database Connected
I can run this command from an ssh tunnel from my local machine but I don't want my local machine to be in control of the server connection, how can I tell EC2 to run npm start on its own and keep it running indefinitely?

dev uncaught exception: listen EADDRINUSE: address already in use :::5000

I am getting the above error
[nodemon] starting `ts-node index.ts`
dev uncaught exception: listen EADDRINUSE: address already in use :::5000 +0ms
[nodemon] app crashed - waiting for file changes before starting...
I tried to find the pid with sudo lsof -i :5000
then kill -9
But then a new process pops up at the same port again. It keeps happening infinitely so I found the parent process with pid 1 and killed it and laptop restarted.
I am unable to run my node app on 5000. Any suggestions?
Edit: My repo is a node app at the root level and has a client folder which is the react app.

Why can't my app run on the intended port in Heroku?

I can't figure out what is the problem with heroku, I've spent 2 days trying to figure out what this error means to no avail.
2021-07-18T04:27:08.741998+00:00 app[web.1]: {"level":30,"time":1626582428741,"pid":44,"hostname":"98a3475f-ac16-4dfa-91e0-46d53d3b5e4c","msg":"Server listening at http://127.0.0.1:34196"}
Server is running as you can see, but when i tried to access my app from the web. This happens..
2021-07-18T04:27:56.941807+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
I have no clue what the problem is. My app is clearly running on the intended PORT as Heroku assigned it to be.
package.json
"scripts": {
"test": "npm run build:ts && tsc -p test/tsconfig.test.json && cross-env TS_NODE_FILES=true tap --ts test/**/*.test.ts",
"start": "npm run build:ts && fastify start -l info dist/app.js",
"build:ts": "tsc",
"dev": "tsc && concurrently -k -p \"[{name}]\" -n \"TypeScript,App\" -c \"yellow.bold,cyan.bold\" \"tsc -w\" \"fastify start --ignore-watch=.ts$ -w -l info -P dist/app.js\"",
"database": "npx prisma migrate dev && npx prisma db seed --preview-feature" },
here's the log from heroku logs --tail
2021-07-19T04:34:45.411610+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-07-19T04:34:45.535520+00:00 heroku[web.1]: Process exited with status 137
2021-07-19T04:34:45.641077+00:00 heroku[web.1]: State changed from starting to crashed
2021-07-19T04:34:45.648836+00:00 heroku[web.1]: State changed from crashed to starting
2021-07-19T04:34:59.197914+00:00 heroku[web.1]: Starting process with command `npm start`
2021-07-19T04:35:02.499184+00:00 app[web.1]:
2021-07-19T04:35:02.499211+00:00 app[web.1]: > app#1.0.0 start /app
2021-07-19T04:35:02.499211+00:00 app[web.1]: > fastify start -l info dist/app.js
2021-07-19T04:35:02.499212+00:00 app[web.1]:
2021-07-19T04:35:03.830676+00:00 app[web.1]: {"level":40,"time":1626669303829,"pid":21,"hostname":"5b062824-4105-40ff-87b7-5846163fdac5","msg":"Allowing all origins"}
2021-07-19T04:35:03.856136+00:00 app[web.1]: {"level":40,"time":1626669303855,"pid":21,"hostname":"5b062824-4105-40ff-87b7-5846163fdac5","msg":"\"root\" path \"/app/assets\" must exist"}
2021-07-19T04:35:05.924577+00:00 app[web.1]: {"level":30,"time":1626669305924,"pid":21,"hostname":"5b062824-4105-40ff-87b7-5846163fdac5","msg":"Server listening at http://127.0.0.1:42948"}
2021-07-19T04:35:59.304046+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-07-19T04:35:59.382557+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-07-19T04:35:59.486461+00:00 heroku[web.1]: Process exited with status 137
2021-07-19T04:35:59.559137+00:00 heroku[web.1]: State changed from starting to crashed
Notice the app ran just fine, but after a while heroku just stopped working indicated from heroku[web.1] after the app started, which is app[web.1]
You call tsc and it take along time to build.
Change build:ts to build and remove npm run build:ts in start script:
Document here
{
"name": "something",
"others key": "here",
"scripts": {
"start":"fastify start -l info dist/app.js",
"build": "tsc",
"others script":"echo 'others'",
}
}
Heroku can only accept applications that's running on 0.0.0.0:{whatever port they assign}. My Fasitfy app was running on 127.0.0.1, which is not the same as 0.0.0.0 apparently. Nevertheless, Heroku doesn't accept any port other than 0.0.0.0

pm2 reload ecosystem.config.js causing many restarts on application

I am experiencing problems reloading the application using the ecosystem.config.js file. When the application is started for the first time, it starts correctly, but when I refresh/reload the application using the ecosystem.config.js file, the application restarts several times causing an error.
My SO is Ubuntu Xenial, PM2 version is 3.2.2 and Node v10.13.0. The application uses the latest version from Express module (4.16.4).
If I reload the application with "pm2 reload app_name", this problem doesn't occur.
The ecosystem.config.js content:
module.exports = {
apps: [{
script: "./index.js",
instances: "max",
exec_mode: "cluster",
kill_timeout: "2000",
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}]
}
When I run the first time:
$ pm2 reload ecosystem.config.js
[PM2][WARN] Applications index not running, starting...
[PM2] App [index] launched (2 instances)
node#ubuntu:/data/$ pm2 logs
[TAILING] Tailing last 15 lines for [all] processes (change the value with >--lines option)
/home/node/.pm2/pm2.log last 15 lines:
PM2 | 2018-11-23T13:14:30: PM2 log: App [index:0] starting in -cluster >mode-
PM2 | 2018-11-23T13:14:31: PM2 log: App [index:0] online
PM2 | 2018-11-23T13:14:31: PM2 log: App [index:1] starting in -cluster >mode-
PM2 | 2018-11-23T13:14:31: PM2 log: App [index:1] online
When I reload the application by name (ex: pm2 reload app_name), the application contiue runnig, but I see some timeouts to kill process:
PM2 | 2018-11-23T14:01:02: PM2 log: pid=11296 msg=failed to kill - retrying in 100ms
PM2 | 2018-11-23T14:01:02: PM2 log: Process with pid 11289 still alive after 6000ms, sending it SIGKILL now...
PM2 | 2018-11-23T14:01:02: PM2 log: pid=11296 msg=failed to kill - retrying in 100ms
PM2 | 2018-11-23T14:01:02: PM2 log: Process with pid 11296 still alive after 6000ms, sending it SIGKILL now...
PM2 | 2018-11-23T14:01:02: PM2 log: App name:index id:_old_0 disconnected
PM2 | 2018-11-23T14:01:02: PM2 log: App [index:_old_0] exited with code [0] via signal [SIGKILL]
PM2 | 2018-11-23T14:01:02: PM2 log: App name:index id:_old_1 disconnected
PM2 | 2018-11-23T14:01:02: PM2 log: App [index:_old_1] exited with code [0] via signal [SIGKILL]
PM2 | 2018-11-23T14:01:02: PM2 log: pid=11289 msg=process killed
PM2 | 2018-11-23T14:01:02: PM2 log: pid=11296 msg=process killed
But, even though timeouts occur the application is running.
When I execute "pm2 reload ecosystem.config.js", the PM2 restart the application several times and one instance fail:
0|index | at Module.load (internal/modules/cjs/loader.js:598:32)
0|index | at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
0|index | at Function.Module._load (internal/modules/cjs/loader.js:529:3)
0|index | at Object. (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:48:21)
0|index | Error: listen EADDRINUSE :::3001
I believe the problem is related to some timeout to properly terminate the http connection of the Express module, but I'm still investigating this.
It has been fixed on the lastest PM2 version, please update:
npm install pm2#latest -g
pm2 update
Make sure you pm2 delete all and then start back your application again, it will work then when doing reload or restart

node-sails app is getting stop in every 24 hours or earlier on server

I have two sails js apps on two servers but my both apps on one server are getting stop in every 24 hours, I usually check both the app in the morning and it shows the following after running
pm2 list or pm2 restart all:-
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2][WARN] No process found
and every time I had to go to their directory and run the command:- pm2 start app.js individually, but both the apps on another server are working correctly.
Please suggest what should I do?
Thanks
Now my service is stoped and after running pm2 logs its showing:
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
########### Starting streaming logs for [all] process
Can not find log files, try to reload logs by executing "pm2 reload <name|all>".
PM2: 2015-07-17 03:27:22: App name:app id:0 online
PM2: child_process.js:935
PM2: throw errnoException(process._errno, 'spawn');
PM2: ^
PM2: Error: spawn ENOMEM
PM2: at errnoException (child_process.js:988:11)
PM2: at ChildProcess.spawn (child_process.js:935:11)
PM2: at exports.spawn (child_process.js:723:9)
PM2: at Object.exports.execFile (child_process.js:607:15)
PM2: at exports.exec (child_process.js:578:18)
PM2: at Object.parseHg [as parse] (/usr/local/lib/node_modules/pm2/node_modules/vizion/lib/hg.js:36:2)
PM2: at /usr/local/lib/node_modules/pm2/node_modules/vizion/lib/vizion.js:16:24
PM2: at /usr/local/lib/node_modules/pm2/node_modules/vizion/lib/identify.js:18:12
PM2: at /usr/local/lib/node_modules/pm2/node_modules/async/lib/async.js:151:21
PM2: at /usr/local/lib/node_modules/pm2/node_modules/vizion/lib/identify.js:12:16
PM2: 2015-07-20 06:23:46: [PM2][WORKER] Started with refreshing interval: 30000
PM2: 2015-07-20 06:23:46: [[[[ PM2/God daemon launched ]]]]
PM2: 2015-07-20 06:23:46: BUS system [READY] on port /root/.pm2/pub.sock
PM2: 2015-07-20 06:23:46: RPC interface [READY] on port /root/.pm2/rpc.sock
and after running pm2 list or pm2 restart all its showing:
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2][WARN] No process found
plz help I am totally stuck in this.
Thanks

Resources