NODEJS Error when try to start a prod enviroment - node.js

hope somebody can help me, Im pretty new dealing with prod enviroment, Im trying to deploy my nodejs backend on aws ec2 linux instance. Using pm2 to run the enviroment but after y use pm2 start ecosystem.config.js --env production command and I log the output I've got this logs:
at process.emit (events.js:327:22)
at emit (internal/child_process.js:876:12)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Error: bind EACCES null:80
at listenOnMasterHandle (net.js:1380:18)
at rr (internal/cluster/child.js:132:12)
at Worker.<anonymous> (internal/cluster/child.js:99:7)
at process.onInternalMessage (internal/cluster/utils.js:47:8)
at process.emit (events.js:327:22)
at emit (internal/child_process.js:876:12)
at processTicksAndRejections (internal/process/task_queues.js:85:21)

Related

Nanoexpress server fails on Heroku & AWS - runs fine locally - cannot trace 'dest.on()' error

Relevant stack-trace below - from Heroku:
2020-04-28T17:49:11.997756+00:00 app[web.1]: Your app is listening on port 14385
2020-04-28T17:49:12.491486+00:00 heroku[web.1]: State changed from starting to up
2020-04-28T17:49:41.748150+00:00 heroku[web.1]: State changed from up to crashed
2020-04-28T17:49:41.649885+00:00 app[web.1]: _stream_readable.js:660
2020-04-28T17:49:41.649896+00:00 app[web.1]: dest.on('unpipe', onunpipe);
2020-04-28T17:49:41.649897+00:00 app[web.1]: ^
2020-04-28T17:49:41.649897+00:00 app[web.1]:
2020-04-28T17:49:41.649898+00:00 app[web.1]: TypeError: dest.on is not a function
2020-04-28T17:49:41.649899+00:00 app[web.1]: at ReadStream.Readable.pipe (_stream_readable.js:660:8)
2020-04-28T17:49:41.649900+00:00 app[web.1]: at SendStream.stream (/app/node_modules/send/index.js:798:10)
2020-04-28T17:49:41.649900+00:00 app[web.1]: at SendStream.send (/app/node_modules/send/index.js:707:8)
2020-04-28T17:49:41.649900+00:00 app[web.1]: at /app/node_modules/send/index.js:774:12
2020-04-28T17:49:41.649901+00:00 app[web.1]: at FSReqCallback.oncomplete (fs.js:172:5)
From AWS (EC2 using a Bitnami instance for NodeJS apps):
Your app is listening on port 8080
_stream_readable.js:666
dest.on('unpipe', onunpipe);
^
TypeError: dest.on is not a function
at ReadStream.Readable.pipe (_stream_readable.js:666:8)
at SendStream.stream (/opt/bitnami/apps/demo/htdocs/node_modules/send/index.js:798:10)
at SendStream.send (/opt/bitnami/apps/demo/htdocs/node_modules/send/index.js:707:8)
at /opt/bitnami/apps/coronavirus-demo/htdocs/node_modules/send/index.js:774:12
at FSReqCallback.oncomplete (fs.js:167:5)
error: Forever detected script exited with code: 1
error: Script restart attempt #1
I see that we seem to be dying on _stream_readable.js:666 where 'dest.on' isn't defined - and I'm way into the weeds of Node at this point - so I'm not sure what I'm looking for, but I find that we're defining this method further down in the file:
https://github.com/nodejs/node/blob/master/lib/_stream_readable.js:852 -
Is this as simple as we're evaluating this _stream_readable file top-down and we haven't defined on() as of line 666 and that's why it's failing?
But why would it work locally? The app runs fine with Nanoexpress server on a Macbook Pro - same package.json and lock files - no devDependencies that make any difference (the only devDependencies are like Mocha and Sinon and Chai for tests)
I've run the app locally with NODE_ENV=production and NPM_CONFIG_PRODUCTION=true (it's a React & Express [Nanoexpress] app) and it boots and I can get what I need running just fine.
It's only when I push to Heroku / AWS that I'm getting this failure. Feels like we're trying to use a function before it's defined...
nanoexpress author here.
nanoexpress works fine on Heroku on my projects, but on AWS did not test, but nanoexpress does not support Lambda/Serverless.
Please check first your code or try PRO version as now it's Free

Errror which crashed the my hosted node.js server file which is run on fore erver command

My node.js server file which is hosted on a server is used by my various applications like mobile apps and desktop app.
At some time my server file which is run through forever command crashes and my whole front end system goes down. Why does the server file crash?
Type Error: Cannot read property 'fragmentedOperation' of null
at Receiver.endPacket (C:\Users\root\Desktop\Server\windowsnodefiles\node-v6.10.3-win-x64\node_modules\socket\node_modules\ws\lib\Receiver.js:247:18)
at Receiver.finish (C:\Users\root\Desktop\Server\windowsnodefiles\node-v6.10.3-win-x64\node_modules\socket.io\node_modules\ws\lib\Receiver.js:483:12)
at Receiver.<anonymous> (C:\Users\root\Desktop\Server\windowsnodefiles\node-v6.10.3-win-x64\node_modules\socket.io\node_modules\ws\lib\Receiver.js:451:33)
at Receiver.add (C:\Users\root\Desktop\Server\windowsnodefiles\node-v6.10.3-win-x64\node_modules\socket.io\node_modules\ws\lib\Receiver.js:95:24)
at Socket.realHandler (C:\Users\root\Desktop\Server\windowsnodefiles\node-v6.10.3-win-x64\node_modules\socket.io\node_modules\ws\lib\WebSocket.js:800:20)
at emit One (events.js:96:13)
at Socket.emit (events.js:188:7)
at readability (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at Nonreactive (net.js:547:20)
error: Forever detected script exited with code: 1
error: Script restart attempt #2
Error: %1 is not a valid Win32 application.
If you are using browserSync library then you can check this link
rollback the browserSync version to ^2.6.4 and it works
or try updating your socket.io package as per this link
Please check if your issue is fixed with the latest release

MongoDB fails to respond on localhost but works for another node app

I'm working on a new node.js app on an old server I use for dev stuff.
Both apps have the mongo URL specified:
var mongoUri = 'mongodb://localhost/node';
but on startup, the old node.js app works fine, but the new one doesn't. The new one returns the following for node server.js
Error: unable to connect to database at mongodb://localhost/node
at NativeConnection.<anonymous> (/var/www/server/server.js:15:9)
at emitOne (events.js:115:13)
at NativeConnection.emit (events.js:210:7)
at /var/www/server/node_modules/mongoose/lib/connection.js:336:19
at args.push (/var/www/server/node_modules/mongodb/lib/utils.js:403:25)
at /var/www/server/node_modules/mongodb/lib/mongo_client.js:254:21
at connectCallback (/var/www/server/node_modules/mongodb/lib/mongo_client.js:933:5)
at /var/www/server/node_modules/mongodb/lib/mongo_client.js:782:11
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
Any thoughts or suggestions would be really appreciated. I've tried everything short of reinstalling mongo at this point :(

Spawn detached electron/node process within built Electron App

I'm building some sort of Server Manager that will mainly be used to configure processes in an "user friendly" environment.
The interface is pretty basic, and allows the creation of servers, configuring and starting/stopping them:
I am using forever-monitor to keep track of the instances, and manage the lifecycle of each server. That is working just great when I run electron directly from my app folder.
However, when I tryed to build and run it from a compiled app, each spawn of a new server instance was actually launching a new electron instance.
I then thought to specify the command in the spawn process, but that lead me to this error:
Uncaught Exception:
Error: spawn node ENOENT
at exports._errnoException (util.js:949:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
at onErrorNT (internal/child_process.js:348:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
And the file where I manage the processes and spawns them is this:
https://github.com/ivanseidel/TournamenterApp/blob/master/controllers/ServerRunner.js#L41-L86

error when starting the server with grunt or node server

I am trying to use the mean stack as described here : http://mean.io/
after install, when making "grunt", there is an error :
debugger listening on port 5858
4 Jan 01:47:40 - [nodemon] reading ignore list
Express app started on port 3000
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
at null.<anonymous> (/mean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:540:74)
at EventEmitter.emit (events.js:106:17)
at null.<anonymous> (/mean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/mean/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:478:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)
4 Jan 01:47:40 - [nodemon] app crashed - waiting for file changes before starting...
I tried the troubleshooting as specified on the site : Updating Grunt, bower and cleaning npm and bower caches worked well. but updating npm gives an error too:
npm ERR! error rolling back Error: Refusing to delete: /usr/local/bin/npm not in /usr/local/lib/node_modules/npm
This looks like a conflict between homebrew and npm.
but anyway i have version 1.3.21 installed.
There is the same error when i am trying node server.
do you have an idea on what i can do to make the server work ?
It may be too easy, but seems like your MongoDB server is not actually running. After having installed Mongo (on your Mac, I assume?), you have to open a Terminal window/tab, run mongod and leave it running (or use screen, etc.). You can try to access MongoDB CLI by typing mongo to make sure the server is running.
#desgnl: if you don't want to run mongod command everytime you are running the grunt, you can always use third party services like MongoDB Hosting: Database-as-a-Service by MongoLab https://mongolab.com Hope this helps too!

Resources