multiple node.js + always = Error: watch EMFILE - node.js

I'm running three node.js applications on one server, all using Foreman to start up the apps through always.js.
Under zero load, one of my apps consistently throws the error Error: watch EMFILE and restarts. That application still works though, despite constantly throwing that error... I've tried to find more information about this error, but there's not a whole lot out there ("too many files open" or "increase ulimit".)
My question is: why would this be happening on an idle web application - and why just one out of three? It's not doing anything... Is it an issue with always.js? (There are two other node apps running through always on this machine though...) Just looking for some info as to what is causing this error, if it's serious, and how it can be resolved.
Thanks!
FYI, here is a relevant excerpt from the console:
01:17:07 web.1 | app listening on http://0.0.0.0:5000
01:17:07 web.1 | NODE_ENV = development
01:17:07 web.1 | opened connection to database!
01:17:07 web.1 | [always] Error: watch EMFILE
01:17:07 web.1 | [always] Error: watch EMFILE
01:17:07 web.1 | at errnoException (fs.js:636:11)
01:17:07 web.1 | at FSWatcher.start (fs.js:663:11)
01:17:07 web.1 | at Object.watch (fs.js:691:11)
01:17:07 web.1 | at Object.oncomplete (/home/jesse/local/nodev0.6.14/lib/node_modules/always/lib/monitor.js:62:36)
01:17:07 web.1 | [always] Restarting app.js with Node

I don't have experience with always.js but got similar errors with other node utilities that use the fs.watch command, which in turn uses linux's inotify API.
You might want to try checking the settings for inotify then:
cat /proc/sys/fs/inotify/max_user_instances
If the file exists, setting it to a higher value might help:
echo 8704 > /proc/sys/fs/inotify/max_user_instances

Related

Why pm2 logs not showing real time in Node js?

I have tried used pm2 modules and use pm2 logs, early pm2 logs are real time and show me everything console it but from today show only at least 15 lines?( can change this line more or less but not show real time "pm2 logs --lines 1000" show at least 1000 but I want show real time logs )
when run "pm2 logs" showing :
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
C:\Users\user.pm2\pm2.log last 15 lines:
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (D:\wamp64\www...\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (C:\Users\user\AppData\Roaming\npm\node_modules\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (D:\wamp64\www...\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (C:\Users\user\AppData\Roaming\npm\node_modules\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
PM2 | Error while getting network statistics Error: not supported
PM2 | at process.nextTick (D:\wamp64\www...\pm2\node_modules\systeminformation\lib\filesystem.js:418:21)
PM2 | at process._tickCallback (internal/process/next_tick.js:61:11)
Why show this error and how resolve it? and why not showing real time logs for me?
all work done :
kill pm2, restart it, update it, update node modules, flush pm2
Thank's

Seeing error Module not found: 'pg-native' in heroku app

I'm attempting to use the postgres add-on with a heroku node app that is also using react.
I'm using this react buildpack to support react inside heroku:
https://github.com/opike/create-react-app-buildpack.git
When I try to add the line:
var pg = require('pg');
I get the following compilation error when I try to run the heroku app locally:
>heroku local web
[OKAY] Loaded ENV .env File as KEY=VALUE Format
[WARN] ENOENT: no such file or directory, open 'Procfile'
[OKAY] package.json file found - trying 'npm start'
4:15:19 PM web.1 | > test-app#0.1.0 start /Users/oliverpike/dev/heroku/ofp-react
4:15:19 PM web.1 | > react-scripts start
4:15:20 PM web.1 | Starting the development server...
4:15:29 PM web.1 | Failed to compile.
4:15:29 PM web.1 | Error in ./~/pg/lib/native/index.js
4:15:29 PM web.1 | Module not found: 'pg-native' in /Users/oliverpike/dev/heroku/ofp-react/node_modules/pg/lib/native
4:15:29 PM web.1 | # ./~/pg/lib/native/index.js 1:13-33
4:15:29 PM web.1 | Error in ./~/pg/lib/connection-parameters.js
4:15:29 PM web.1 | Module not found: 'dns' in /Users/oliverpike/dev/heroku/ofp-react/node_modules/pg/lib
4:15:29 PM web.1 | # ./~/pg/lib/connection-parameters.js 2:10-24
I was able to get past this issue by doing an:
> npm i pg-native
as described here:
https://github.com/brianc/node-pg-native
as well as an
> npm i dns
for the dns issue.
The odd thing was that I didn't need to explicitly install these packages in my other heroku app that is using postgres.

Localhost POST request for GroupMe Bot

I'm trying to test a GroupMe bot that I made using Node.js. I'm using the Example Bot by GroupMe. After running foreman start and
curl -X POST -d \cool guy\ localhost:5000 (from a similar question), I get the error curl: (1) Protocol "guy http" not supported or disabled in libcurl. I tried wrapping the message in double quotes, but that only resulted in a syntax error. How can I fix this?
Edit:
I tried
$ curl -X POST -d "cool guy" localhost:5000
and got the following error from foreman:
22:04:16 web.1 | started with pid 5788
22:04:32 web.1 | undefined:1
22:04:32 web.1 | cool guy
22:04:32 web.1 | ^
22:04:32 web.1 | SyntaxError: Unexpected token c
22:04:32 web.1 | at Object.parse (native)
22:04:32 web.1 | at Object.respond (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\bot.js:11:24)
22:04:32 web.1 | at apply (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\node_modules\director\lib\director\router.js:448:19)
22:04:32 web.1 | at _every (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\node_modules\director\lib\director\router.js:30:9)
22:04:32 web.1 | at Router.invoke (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\node_modules\director\lib\director\router.js:454:5)
22:04:32 web.1 | at IncomingMessage.parseAndInvoke (C:\Users\Nicky\Documents\GitHub\groupme-jarvis\node_modules\director\lib\director\http\index.js:175:10)
22:04:32 web.1 | at IncomingMessage.g (events.js:199:16)
22:04:32 web.1 | at IncomingMessage.emit (events.js:104:17)
22:04:32 web.1 | at _stream_readable.js:908:16
22:04:32 web.1 | at process._tickCallback (node.js:355:11)
22:04:32 web.1 | exited with code 1
22:04:32 system | sending SIGKILL to all processes
Add http:// in front of localhost. Libcurl, the library that curl uses, supports many different protocols. Curl is correctly assuming http, but seems to be have a bug.
Edit: after reading the question again, I see that curl was compiled without http support. If you compiled it yourself, make sure to enable http support. If you installed it using a distributions package manager, try reinstalling.

Port in use when launching Node.js app with Heroku Foreman

I am trying to deploy my node.js app to heroku but when I try to launch it locally using foreman I am getting Error: listen EADDRINUSE. I have run a netstat and grepped for the port nothing else is using it and the server starts without issue when running directly as a node http server.
The app I am trying to deploy is using mongo and redis I am not sure if these components will effect the server starting with Foreman. Does anyone have any suggestions on areas I could look at for potential bugs?
foreman start
01:37:18 web.1 | started with pid 1835
01:37:18 web.1 | /usr/local/foreman/lib/foreman/process.rb:66: warning: Insecure world writable dir /usr/local in PATH, mode 040777
01:37:19 web.1 | events.js:72
01:37:19 web.1 | throw er; // Unhandled 'error' event
01:37:19 web.1 | ^
01:37:19 web.1 | Error: listen EADDRINUSE
01:37:19 web.1 | at errnoException (net.js:863:11)
01:37:19 web.1 | at Server._listen2 (net.js:1008:14)
01:37:19 web.1 | at listen (net.js:1030:10)
01:37:19 web.1 | at Server.listen (net.js:1096:5)
01:37:19 web.1 | at Function.app.listen (/Users/craig/Documents/Sandboxes /xxx/node_modules/express/lib/application.js:535:24)
01:37:19 web.1 | at Object.<anonymous> (/Users/craig/Documents/Sandboxes/xxx/web.js:25:5)
01:37:19 web.1 | at Module._compile (module.js:456:26)
01:37:19 web.1 | at Object.Module._extensions..js (module.js:474:10)
01:37:19 web.1 | at Module.load (module.js:356:32)
01:37:19 web.1 | at Function.Module._load (module.js:312:12)
01:37:19 web.1 | exited with code 8
01:37:19 system | sending SIGTERM to all processes
SIGTERM received
Thanks.
--Additional information--
The procfile just has one entry:
web: node web.js
and I have set the listener up as follows:
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
I just ran into this on OS X. It looks like foreman picks port 5000 by default, which seems to conflict with Bonjour/mDNS/UPNP services. (From what I've read. I haven't taken the time to pick out which it is.)
However, you can change the port that foreman uses in two ways: specify the port on the command line or create a .foreman file with the port number specified there.
Good luck and happy coding!
I had the same issue, Error: listen EADDRINUSE means that a Node server is already running.
Check that you are not running a Node server for the same project locally. If you are working on a GitHub synced project locally (on port 5000 for instance) which is tied to Heroku you cannot run a local Node server for that project as the port will be in use twice.
I was actually running a Node server on a project in a different Terminal window and didn't notice immediately.

Can't start foreman cos node.js complains about some obscure module it can't find

trying to get a project working on my debian vm but foreman refuses to start. the node.js error message is not very helpful cos it doesn't even tell me what module can't be found.
sissi#debian:/media/fancystuff$ foreman start
22:05:33 web.1 | started with pid 2949
22:05:33 web.1 |
22:05:33 web.1 | module.js:337
22:05:33 web.1 | throw new Error("Cannot find module '" + request + "'");
22:05:33 web.1 | ^
'2:05:33 web.1 | Error: Cannot find module '/media/fancystuff/web.js
22:05:33 web.1 | at Function._resolveFilename (module.js:337:11)
22:05:33 web.1 | at Function._load (module.js:279:25)
22:05:33 web.1 | at Array.0 (module.js:484:10)
22:05:33 web.1 | at EventEmitter._tickCallback (node.js:190:38)
22:05:33 web.1 | process terminated
22:05:33 system | sending SIGTERM to all processes
btw 1: the error message is the same no matter if web.js is there of if it's deleted....which just adds to my confusion.
btw 2: "foreman check" gives me "valid procfile detected (web)"
sigh.
From this line:
'2:05:33 web.1 | Error: Cannot find module '/media/fancystuff/web.js
it looks like there is a non-printing character at the end of the line in your Procfile where you call node web.js since the ' character that was put after module name string ended up at the beginning of the line.
Editing Procfile and making sure that that special character is gone, your problem will probably be solved. I could replicate this on my Debian dev. server by adding <32 characters at the end of the line after web.js before EOL.
Most probably the Procfile was coppied from different OS that append carriage return e.g \r\n that not compatible with foreman. Just remove the trailing spaces or character in the Procfile and rerun. Or the simplest is to remove the Procfile and create using same OS
Example Procfile:
web: node web.js
And start the apps:
ubuntu#yadayada:~/heroku/web$ foreman start

Resources