NodeJS: forever.js throws binding error : EROFS read only file system - node.js

Okay, so I am using nodejitsu's forever(v0.11.1) module to keep my NodeJS(v0.10.28) + expressJS(3.5.1) server running on VPS(CentOS-6.4). Everything was working smoothly untill recently when I started getting following error while running command: forever start server.js As soon as I run this command I got the following error:
I tried to see the file: ls - l /root/.forever/tVYM.log, No such file was found
When I tried to start my node server using pm2, I got the following error:
I don't understand why is this happening even if I am root(su) user. Also, if I try to edit my server.js file, CentOS won't let me edit file and warns me about insufficient privilege.
But when I rebooted VPS and used forever, things were okay again but after some time, my server went down again and when I used forever to run my node app, forever threw the same error. I just can not see reason behind this. Thanks in advance

Related

Make nodemon auto-restart a program on crash without waiting for file changes at custom error?

I'm building an E-commerce site, where there's an Authentication system.
I noticed that if the client login with a wrong user or password, the backend/server that works with nodemon will crach and hang in there crashed till i restart manually nodemon. This is example output error of the nodemon crash:
[nodemon] app crashed - waiting for file changes before starting...
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent
to the client
Ofcourse, when server crashes, client can no more access or do login again till server restarts.
After some googling, i found this question and this repository that fix my problem but particulary and not as expected precisely, i dont want nodemon to restart forever on any error that occure ofcourse, but only with specifics errors that i set them -like Authentication errors as i mentionned above-.
So, my idea/question is: is there anyway to get nodemon restarts by itself in some cases of failures or errors (NOT ALL)?
Seems like you a referring to a production situation, and nodemon is a development node server, which is not intended for use in production, as the intro states:
nodemon is a tool that helps develop Node.js based applications by
automatically restarting the node application when file changes in the
directory are detected.
You should use node.js in production, instead of nodemon.
For managing your node server in production, you could use a process manager like PM2..
That said, an authentication server that crashes every time a user uses a wrong password seams very ineffective in handling a common use case. So I would advise to start with fixing the root cause, which is the buggy server, and then for recovery from incidental crashes use something like PM2.
PS:
The error you are getting looks like an express error you get when you send a response (in this case an error response) without exiting the function e.g. by using return. Because you are not returning, another res.send is called, which causes the 'ERR_HTTP_HEADERS_SENT' error. See this answer.
This is really bad since it can send your program into a loop of restarting, but if you really want it, replace app.js with your file's name and try this:
nodemon -x 'node app.js || copy /b app.js +,,'
Linux version:
nodemon -x 'node app.js || touch app.js'
Next time try a little googleing before you ask since it is most likely faster.

"Process out of memory" error after installing node from source

I'm trying to install NodeJS on shared hosting. I downloaded the source from
https://nodejs.org/en/download/
and followed the usual install procedure with ./config --prefix="$HOME/local".
It compiles without error. However, when I try to run it, I get the following error:
installing /kunden/homepages/32/d690510543/htdocs/local/include/node/zconf.h
installing /kunden/homepages/32/d690510543/htdocs/local/include/node/zlib.h
(uiserver):xxxxxxxx:~/node-v8.11.2$ which node
/kunden/homepages/32/d690510543/htdocs/local/bin/node
(uiserver):xxxxxxxx:~/node-v8.11.2$ node
#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
Illegal instruction
However, I can get the version
$ node -v
v8.11.2
and help.
Nevertheless, I can't run a script
(uiserver):xxxxxxxx:~$ cat hello.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
(uiserver):xxxxxxxx:~$ node hello.js
#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
Illegal instruction
Nor can I enter the REPL:
(uiserver):xxxxxxxx:~$ node -i
#
Fatal error in , line 0
API fatal error handler returned after process out of memory
#
Illegal instruction
I had the same issue and what i realized was that it was only occuring when i use mlab sandbox mongo db.Initially everything was ok even with mlab mongo db but all over sudden i the error started appearing .I changed to locally installed mongodb and all was well,i deleted my mlab mongo db collections and changed back to mlab,all was well again.I guess the issue is with mlab free tier limitations
When I execute my Vue.js project with command:
npm run dev
in webstorm console, the console output:
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
Then when I restart use command:
npm run dev
webstorm crashes, I restart webstorm and use command:
npm run dev
a second time, and it works. So I think it is because that my computer memory is not enough when webstorm starts too many child processes.
Had the same issue (and afaik the same hosting provider). However, installing node through nvm, like described e.g. at https://stackoverflow.com/a/33857377/1680728 did solve the issue for me. I do not know whether its some environment setting or has to do with the fetched binaries/version.
So, I cannot solve the "Process out of memory" error, but I guess the real problem was to have any nodejs version running on a shared host.
I had the same issue and I close my webstorme and try again

NodeJS app (Keystone JS) runs fine when started manually, restarts over and over when started with pm2

I am using Ubuntu 16.04 x 64 and I'm running into an issue -
When I run my Keystone JS app manually by typing in "node keystone", the app runs fine and I can view it in my browser like normal.
However, when I start the app using pm2, the app fails immediately and restarts consecutively.
I think it is because keystonejs has a known "error" that is not a real error, but just a warning when it starts.
From the "keystone-out-0.log" file -
Error ...node_modules/bson/build/Release/bson.node: invalid ELF header
However, in the "keystone-error-0.log" file, it gives me a different error that does not occur when I run it manually -
Error: ENOENT: no such file or directory, open '.env'
Any one faced anything similar?
Thanks

Running node.js server with mongodb error

I'm still new to node.js and mongodb. Now I'm trying to solve this problem.
I have instructions to run my server without any problems, I follow them and yes my server works. But when I switched the server off then run it again I face this bug:
[vagrant#localhost ~]$ node /opt/inapsrv/app/app.js
app-api listening at http://0.0.0.0:7000
/opt/inapsrv/node_modules/fileupload/lib/modules/file.js:23
throw error
^
Error: ENOENT, mkdir 'data/imagex/'
And here is the line of the directory above taken from app.js file:
var imagePath = 'data/imagex/';
I tried to:
make vagrant and mongo users as super users and they have the root permissions.
to run "sudo node /opt/inapsrv/app/app.js"
run "forever /opt/inapsrv/app/app.js"
and it didn't work.
I don't know why it successfully ran the first time, and then it didn't!
Any help?
I suspect you're using node module fileupload for the upload job. The source code fragment in fileupload that throws your error can be found here.
The problem with the code used in fileupload module is that it does not create recursive directories since fs.mkdir is used. To fix your issue try to create the upload directory or at least data upfront. You could do this by a npm script, in app.js using the mkdirp or simply by a shell script.
The problem described is not related to mongodb or mongoose.

Running meteor.js application on your own server

I am trying to run my meteor application on my local network so that when I am off-line I can still use the application on any devices connected to my network. I have been following http://ox86.tumblr.com/post/45184656062/running-your-meteor-js-application-on-your-own-server as a basic tutorial on how to do this. I am new to mongodb and node.js, which causes some trouble. However it seems that everything is working except I do not know where my app is running or what the address is? For example after I complete step 4 from the tutorial
export PORT=8080
export MONGO_URL=mongodb://bill:123456#localhost:27017/dbName
after navigating inside my bundle where main.js is I use
forever start main.js
There are no errors, but I don't know where my app is or if it is even working. Once again I am new to this idea of hosting my own meteor app. Any ideas or suggestions of what I am doing wrong. Also an explanation of the process would be much appreciated. Thanks for the help!
It's likely you have errors. You should check with forever logs main.js to see what you get.
From what it looks like you may have missed the ROOT_URL variable too.
export ROOT_URL=http://www.yoururl.com
export PORT=8080
export MONGO_URL=mongodb://bill:123456#localhost:27017/dbName
forever start main.js
The best check would be to see what you get in the forever logs. Also you may have to install fibers (before you start your app) if you have some error in your logs like invalid ELF header
cd bundle/programs/server/node_modules
rm -r fibers
npm install fibers#1.0.1

Resources