NodeJS deployment error - node.js

I've a project in NodeJS. I've built a framework based on ExpressJS, SocketIO, MongoDB and it works pretty well in local version.
I'm trying to deploy this project on a DigitalOcean Droplet (Debian) ; I've installed everything required (npm, node, mongo). It starts to launch the daemon and I got a big error.
To launch my app I use npm start with the following scripts
"scripts": {
"start": "./node_modules/.bin/supervisor DEBUG=unicorn ./bin/www"
}
Then it goes like that
Starting child process with 'node ./bin/www'
01:59:19 - info: Try to connect to MongoDB via Mongoose ...
01:59:19 - info: Loading Socket.io module ...
Option log level is not valid. Please refer to the README.
01:59:19 - info: Reboot system initialized (pre_starters)
01:59:19 - info: --------------------
01:59:19 - info: Unicorn (Black Mamba (0.0.4a))
01:59:19 - info: -> Welcome aboard !
01:59:19 - info: -> Your app is ready to use.
01:59:19 - info: --------------------
01:59:19 - info: Express server listening on port 8003
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, open 'logs/app.log'
Program node ./bin/www exited with code 8
So i'm searching a solution for more than 3 hours now, people say it's usually because the port is busy, I checked all the processes and the port they use, and found nothing.
I also tried to change the port of Express and SocketIO (80, 8080, 3000, etc.) but it didn't change anything ...
Do you have any other idea i could try ? Or better a miraculous solution ? Thanks people ;)
PS : I also did a clean npm install from the server to have no problem with the packages compatibilities from my local version to the server.

The problem is this:
Error: ENOENT, open 'logs/app.log'
It means that your script is trying to open a logfile but fails. Since the error isn't getting caught, the script crashes.
My guess is that it's not being started in the directory you assume (one that has logs/ as a subdirectory). So you should either make sure that your script is started in the right directory, or you should use an absolute path to the logfile.

Related

Cannot connect to my databse addon on heroku

I attempted to use the command Heroku pg:psql to connect to my database addon in heroku but got a response below
--> Connecting to postgresql-regular-61345
unrecognized win32 error code: 123could not find a "psql" to execute
unrecognized win32 error code: 123could not find a "psql" to execute
psql: fatal: could not find own program executable
! psql exited with code 1
After using the heroku logs --tail command i got the following errors
sh: 1: nodemon: not found
Process exited with status 127
State changed from starting to crashed
I can also see all processes stopping with SIGTERM and the process exiting with status 143
Resolution steps I have taken
Verified that the environment variables have the path for installed postgress14 on my PC
Added a procfile to the root file in my backend code and spcified "web: node matthewfaceappback/server.js in the file"
Changed my set port to a variable port using process.env.PORT || 3000
Set all environment variable including my database url(set by default) on config variable in heroku
Verified there is a start up script
Updated all my packages using "npm update". after doing this i started expereincing the issue of processes stopping with SIGTERM and the process exiting with status 143
I moved nodemon from devDependencies to dependencies. nodemon version is 2.0.15
In package.json i inputed an engines parameter using the version of node in my case
{"engines": {
"node": "14.17.4"
}}
I restarted heroku using "heroku restart"
Below are links to the screenshots of the error
https://www.dropbox.com/s/5bdbyi9e99lbxhu/pic1.PNG?dl=0
https://www.dropbox.com/s/41euniaes5q68c9/pic2.PNG?dl=0
https://www.dropbox.com/s/50oqzbwmwrqogax/pic3.PNG?dl=0
Put nodemon back in the devDependencies and add it as a second node script in package.json:
"scripts": {
"start": "node matthewfaceappback/server.js",
"dev": "nodemon matthewfaceappback/server.js"
},
These two errors are completely unrelated.
The database connection error
The first issue, which I believe is the one you actually care about at the moment based on the title of the question, indicates that the Heroku CLI can't find a PostgreSQL client on your local machine.
The documentation makes the following recommendation
Set up Postgres on Windows
Install Postgres on Windows by using the Windows installer.
Remember to update your PATH environment variable to add the bin directory of your Postgres installation. The directory is similar to: C:\Program Files\PostgreSQL\<VERSION>\bin. Commands like heroku pg:psql depend on the PATH and do not work if the PATH is incorrect.
If you haven't already installed Postgres locally, do so. (This is a good idea anyway as you should be developing locally and you'll probably need a database.)
Then make sure to add its bin/ directory to your PATH environment variable.
The Nodemon error
The second issue is because you are trying to use nodemon in production. Heroku strips development dependencies out of Node.js applications after building them, which normally makes sense. Nodemon is a development tool, not something that should be used for production hosting.
Depending on the contents of your package.json, this might be as simple as changing your start script from nodemon some-script.js to node some-script.js. Alternatively, you can add a Procfile with the command you actually want to run on Heroku:
web: node some-script.js
See also Need help deploying a RESTful API created with MongoDB Atlas and Express

setting up and configuring mean.js app deployment on openshift

I have a MEAN.js app that I deployed to openshift server doing the following steps:
1- setup client tools rhc, git, etc..
following this tutorial openshift tutorial
result: successfully authenticated through rhc ssh to my openshift domain
2- created a new app through the web console using the open shift provided cartridge Nodejs cartridge on openshift
3- added a mongodb cartridge the the application through openshift web console
4- Now I did a step to install bower manually to avoid committing & pushing libraries through git
using rhc ssh command on the terminal i issued npm install -g bower on the console, and it seemed to work fine, bower installed successfully
5- downloaded the nodejs app from github as guided through the setup guide now i got the folder structure of the app deployed on the server locally
6- I needed to include the following in the app folder to successfully deploy my app to the server
a- npm dependencies in the package.json file
b- bower.json file ( later i should be able to run bower install to install bower dependencies in the repo) was not successful I don't have sudo permissions on the directory
c- all the files and folder structure required to run my project
d- lines of code that setup the server to run using the configuration files that bind mongoose.js, with express.js , passport, and to listen on port 3000
to do this I included code into the existing app.js file that already setup the node server to run `
var mongoose = require('./config/mongoose'),
express = require('./config/express'),
passport = require('./config/passport');
var db = mongoose();
var app = express();
var passport = passport();`
e- commit all and push done that
result : through the rhc terminal was successful deployment
but when I visit the link on the browser I got a
503 Service Unavailable No server is available to handle this request.
I went back to the terminal and rhc ssh to the openshift server, then ran taill_all to see whats going on in the logs found the following on repeat in the terminal
==> app-root/logs/haproxy.log <== [WARNING] 134/132624 (39619) : Stopping proxy express in 0 ms. [WARNING] 134/132624 (39619) : Proxy
stats stopped (FE: 2 conns, BE: 0 conns). [WARNING] 134/132624 (39619)
: Proxy express stopped (FE: 9 conns, BE: 103 conns). [WARNING]
134/132624 (75275) : config : log format ignored for proxy 'stats'
since it has no log address. [WARNING] 134/132624 (75275) : config :
log format ignored for proxy 'express' since it has no log address.
[WARNING] 134/163313 (75275) : Server express/local-gear is DOWN for
maintenance. [ALERT] 134/163313 (75275) : proxy 'express' has no
server available! [WARNING] 134/163353 (75275) : Server
express/local-gear is UP (leaving maintenance). [WARNING] 134/163355
(75275) : Server express/local-gear is DOWN, reason: Layer4 connection
problem, info: "Connection refused", check duration: 0ms. 0 active and
0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in
queue. [ALERT] 134/163355 (75275) : proxy 'express' has no server
available!
==> app-root/logs/nodejs.log <==
at require (internal/module.js:20:19)
at module.exports (/var/lib/openshift/57375ced7628e1e8f00001bd/app-root/runtime/repo/config/express.js:54:3)
at Object. (/var/lib/openshift/57375ced7628e1e8f00001bd/app-root/runtime/repo/app.js:46:11)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32) { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to
load c++ bson extension, using pure JS version { [Error: Cannot find
module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson:
Failed to load c++ bson extension, using pure JS version Warning:
connect.session() MemoryStore is not designed for a production
environment, as it will leak memory, and will not scale past a single
process.
The problem is MEAN.IO cartidge provided by openshift is not the same project structure, or dependencies as any custom MEAN.js app, which is essentially a node.js app with mongodb and express.js for server side api routing, so it's not usable in this case such as the suggestion in the following question : suggestion to use mean.io cartridge to deploy a mean.js app
kindly help direct me towards a more direct way to deploy & configure any mean.js app on openshift, suggestions to use other servers are welcomed if there's a clear successful past experience, thanks
If you choose to edit code directly on the server (avoiding committing and pushing your changes), your work will be lost if your app ever needs to be restored or rebuilt.
Bower is usually used as a generator, to scaffold code locally (before you commit and push your changes). I don't think bower works correctly on OpenShift since it expects the $HOME dir to be writable.
I'd try doing this work locally, then commit and push the result.

Error: Cannot find module '/usr/lib/node_modules/node-inspector/lib/InjectorServer.js'

I work on a mean.js application (on top of express.js > node.js).
I succeed to debug it locally (on kubuntu) with node inspector, no problem.
But I fail to debug it remotely (from an ubuntu server) , after I pushed my app on the network.
I get this error on the devtools console:
Page.getResourceContent failed. Error: ENOENT, open
'/home/remi/publisher-server/server.js' Error: Cannot find module
'/usr/lib/node_modules/node-inspector/lib/InjectorServer.js'
But the server.js's file permissions are 775, and are owned by me.
If you look at this screenshot you can see that the browser access to all files tree and contents:
However, if you look at that one, you'll see that only the server.js seems unreadable (content tab is empty):
Here are the steps I follow:
I login my server with this ssh options to redirect the5858 port
ssh -L 5858:localhost:5858 my-remote-host
From the ssh session I run the app with --debug option:
$ cd ~/publisher-server
$ node --debug server.js
debugger listening on port 5858
Application loaded using the "development" environment configuration
MEAN.JS application started on port 3000
From my laptop I run :
$ node-inspector
Node Inspector v0.10.1
Visit http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858 to start debugging.
Cannot resolve real path of /home/remi/publisher-server/server.js: Error: ENOENT, lstat '/home/remi/publisher-server'
You can notice the last line that throw the error that I found again in the devtools console when I finally browse http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858 :
Page.getResourceContent failed. Error: ENOENT, open
'/home/remi/publisher-server/server.js' Error: Cannot find module
'/usr/lib/node_modules/node-inspector/lib/InjectorServer.js'
This makes me a bit crazy, what I'm making wrong ?

Error running grunt/starting server.js

For some quick background, I am following a MEANio tutorial found here. Now, I am at the part where I have run mean init, it has finished, and then cd into the project directory and run
npm install
After fixing a brief JSON syntax issue inside package.json (the end of the file was slightly mis-typed), I attempted to run
grunt
Hook task, clean, jshint, and csslint all ran fine, and then when I get to the portion of the build script that runs
node --debug server.js
I run into errors
events.js:72
throw er; // Unhandled 'error' event
Error: listen EADDRNOTAVAIL
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1024:19)
at listen (net.js:1065:10)
at net.js:1147:9
at asyncCallback (dns.js:68:16)
at Object.onanswer [as oncomplete] (dns.js:121:9)
[nodemon] app crashed - waiting for file changes before starting...
I am pretty clueless about the inner workings of Node, does anyone know what this error refers to? I followed the MEANio tutorial nearly exactly, with the exception of where my node is at, I just have it in a folder that I have added to my $PATH in my .bashrc file. Could someone give me some advice on what files to check/debug?
The EADDRNOTAVAIL error typically occurs when you are trying to run a server on a port that is already in use. That tutorial suggests that the port would be 3000 (which is a typical default for Node applications). You should check to see that you do not have anything else running on port 3000 already.

node.js & pdfjs 'Unknown file open flag'

I have pdfjs installed running on node.js started with nohup. I am able to start node fine and port 81 is open in the firewall. As soon as I attempt to go to it in the browser it logs the following error in the nohup.out log and node.js stops. The crazy bit is that I have this working on a temporary server that was created from an image of this one to insulate the live server while a worked all this out. Now I can't seem to replicate the success I had. I can supply the code from specific files if it would be helpful, just let me know which ones.
Server running at http://mydomain.com:81/
fs.js:186
throw new Error('Unknown file open flag: ' + flag);
^
Error: Unknown file open flag: rs
at stringToFlags (fs.js:186:13)
at Object.open (fs.js:224:44)
at new <anonymous> (fs.js:1062:6)
at Object.createReadStream (fs.js:1010:10)
at serveRequestedFile (/var/path/to/tools/pdfjs/test/webserver.js:211:23)
at Object.statFile [as oncomplete] (/var/path/to/tools/pdfjs/test/webserver.js:157:7)
Solved: Reinstalling node.js was the solution. If people encounter this error, it is likely that node either isn't installed or wasn't installed successfully. Try installing/reinstalling to correct.

Resources