I follower every instruction for installing a MEAN stack application.
At the end of it all I run grunt and when I go to http://localhost:3000 I get the following error:
Running "clean:0" (clean) task
Running "jshint:all" (jshint) task
>> 47 files lint free.
Running "csslint:src" (csslint) task
>> 5 files lint free.
Running "concurrent:tasks" (concurrent) task
Running "nodemon:dev" (nodemon) task
Running "watch" task
Waiting...
[nodemon] v1.0.20
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node --debug server.js`
debugger listening on port 5858
Mongoose: packages.findOne({ name: 'config' }) { fields: undefined }
3000
Mean app started on port 3000 (development)
Mongoose: users.ensureIndex({ email: 1 }) { safe: undefined, background: true, unique: true }
Mongoose: users.ensureIndex({ username: 1 }) { safe: undefined, background: true, unique: true }
GET / 304 41.185 ms - -
events.js:72
throw er; // Unhandled 'error' event
^
Error: ENOENT, open '/var/www/finnviz/bower_components/bootstrap/dist/css/bootstrap.css'
[nodemon] app crashed - waiting for file changes before starting...
I searched and found this answer, but this does not seem to be the case, when I run ps aux | grep node I dont get any running process:
trufa 14763 0.0 0.0 23492 956 pts/14 S+ 15:39 0:00 grep --color=auto node
I searched through many answers but none seem to apply. Some suggest to change the port. I tried it and the error is the same.
Any suggestions as to how to proceed?
Sometimes the automatic bower install does not work if you run npm with sudo.
I would recommend setting up npm so it does not require sudo.
Try running $ bower install from your project root, and then restart the server.
you had run another server using the same port 8080.
Related
So, basically I am setting up my local server using node.js and nodemon. It starts well on localhost but when I refresh the page or open another page, the server crashes giving me this unhandled 'error' event. I have searched through some solutions and tried reinstalling the dependencies after removing the cache by using npm cache clean --force. There is an image attached showing the error.
When I start my server using nodemon
After refreshing the landing page or going to other page
In case these images doesn't show up this is my whole return from vs code from starting the server to when I refresh the page or navigate to another page:
> nodemon app.js
[nodemon] 2.0.12
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`
server listening on port: 5000
events.js:377
throw er; // Unhandled 'error' event
^
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at writeAfterEnd (_http_outgoing.js:694:15)
at ServerResponse.end (_http_outgoing.js:815:7)
at Server.<anonymous> (C:\Users\SUJAL\OneDrive\Desktop\VS code\web development\NodeJs\nodejs\app.js:17:7)
at Server.emit (events.js:400:28)
at parserOnIncoming (_http_server.js:897:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)
Emitted 'error' event on ServerResponse instance at:
at writeAfterEndNT (_http_outgoing.js:753:7)
at processTicksAndRejections (internal/process/task_queues.js:83:21) {
code: 'ERR_STREAM_WRITE_AFTER_END'
}
[nodemon] app crashed - waiting for file changes before starting...
If you can even help with a temporarily solution, it will be great.
Make sure the port you're using is not in use by other services. Or, use a different port.
I had the same issue. Later realized port 5000 was being used by another service on my pc. Switched it to a different one and worked fine.
I am trying to run a Node app on a newly created Heroku App from their web. I followed their steps and still I am getting errors when displaying app status.
I followed the Node.js getting started section without the heroku create command since I already created from the web.
So when I run: heroku ps:scale web=1 it shows me:
Scaling dynos... done, now running web at 1:Free
But when running heroku ps:
=== web (Free): npm run start (1)
web.1: crashed 2018/10/25 11:25:49 -0300 (~ 8m ago)
So my logs on heroku logs --tail show me this error:
2018-10-25T14:25:44.000000+00:00 app[api]: Build succeeded
2018-10-25T14:25:46.451739+00:00 heroku[web.1]: Starting process with command npm run start
2018-10-25T14:25:49.113832+00:00 app[web.1]:
2018-10-25T14:25:49.113864+00:00 app[web.1]: > my-app#1.0.0 start /app
2018-10-25T14:25:49.113866+00:00 app[web.1]: > node server.js
2018-10-25T14:25:49.113867+00:00 app[web.1]:
2018-10-25T14:25:49.418151+00:00 app[web.1]: events.js:167
2018-10-25T14:25:49.418191+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-10-25T14:25:49.418193+00:00 app[web.1]: ^
2018-10-25T14:25:49.418194+00:00 app[web.1]:
2018-10-25T14:25:49.418196+00:00 app[web.1]: Error: listen EACCES 0.0.0.0:80
So I checked if I made a mistake while setting all up.
I use a simple Express routing and server with this code:
app.get('/', (req, res) => { ... });
app.listen(80, err => {
if(err) throw err;
console.log("%c Server running", "color: green");
});
Also I made sure I added engines to package.json:
"scripts": {
"start": "node server.js"
},
"engines": {
"node": "10.11.0",
"npm": "6.4.1"
},
I've also created a Procfile file in the root path with web: npm run start inside.
So when everything is checked I just run these commands and everything looks great until I check the logs or visit the app:
git commit -am "my commit text"
git push heroku master
I see this in the logs:
remote: -----> Compressing...
remote: Done: 18.3M
remote: -----> Launching...
remote: Released v12
remote: https://my-app.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/my-app.git
3656da0..f1eb078 master -> master
So... Any suggestions on what am I doing wrong? Thanks in advance.
You need to provide port for app to listen on in environment variable.
What heroku does is it runs our app on dynamic port.
Try using this:
const PORT = process.env.PORT || 3000;
app.listen(PORT, err => {
if(err) throw err;
console.log("%c Server running", "color: green");
});
Also you shouldn't bind the port to 80, as it is a reserved standard
http port.
Heroku dynos expose a dynamic port for your app to bind to. This value is exposed in the $PORT env var. You must change your code to bind to this port instead.
const port = process.env.PORT || 3000;
app.listen(port, err => {
if(err) throw err;
console.log("%c Server running", "color: green");
});
I'm running http://socketcluster.io/ and I want to restart my workers whewnever a file changes. However, nodemon server.js fails as soon as it tries to restart with an endlessly-repeating wall of:
1445633138359 - Origin: Worker (PID 44372)
[Error] Error: connect ECONNREFUSED /var/folders/fj/yzfd3_tn7xd0smz7j6s093mh0000gn/T/socketcluster/6879fe94-ed92-4188-b1d7-cb187a5ade4e_b68fcded6c/b0
at Object.exports._errnoException (util.js:874:11)
at exports._exceptionWithHostPort (util.js:897:20)
at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
1445633138362 - Worker 0 exited - Exit code: 0
How can I safely restart SocketCluster to load the new changes?
nodemon sends the SIGUSR2 signal to the main (Master) process. SocketCluster (correctly) interprets this as as a request to reboot the workers. Unfortunately, there's an open issue where things are not shut down properly and errors fly all around.
There are two options:
You can add the code from the linked issue:
house.addShutdownHandler(function(ctx, next){
socketCluster.killWorkers();
socketCluster.killBrokers();
next();
});
or use forever to send a "restart everything" signal:
forever -w --killSignal=SIGTERM server.js
Improvements were made for nodemon in SC version 5.0.23 or later.
Make sure that you pass killMasterOnSignal: true when instantiating SocketCluster in your code (server.js file) - This setting is necessary for nodemon to work.
I have been trying to install the MEAN stack using the following tutorial:
http://www.bossable.com/303/install-mean-stack/#comment-1526
I am using webstorm and MongoDB.
However I have been unsuccessful and I keep getting errors. Everytime I connect to localhost:3000 I get the following error:
C:\meanproject>grunt
Running "jshint:all" (jshint) task
>> 55 files lint free.
Running "csslint:all" (csslint) task
>> 2 files lint free.
Running "concurrent:default" (concurrent) task
Running "nodemon:dev" (nodemon) task
Running "watch" task
Waiting...
[nodemon] v1.2.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: app/views/**/*.* gruntfile.js server.js config/**/*.js app/*
*/*.js
[nodemon] starting `node --debug server.js`
Debugger listening on port 5858
Application loaded using the "development" environment configuration
{ [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
MEAN.JS application started on port 3000
C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection
\base.js:246
throw message;
^
Error: Error setting TTL index on collection : sessions
at C:\meanproject\node_modules\connect-mongo\lib\connect-mongo.js:169:23
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.
js:1499:46
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.
js:1632:20
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cur
sor.js:170:22
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cur
sor.js:714:39
at Cursor.close (C:\meanproject\node_modules\mongoose\node_modules\mongodb\l
ib\mongodb\cursor.js:1009:5)
at commandHandler (C:\meanproject\node_modules\mongoose\node_modules\mongodb
\lib\mongodb\cursor.js:714:21)
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.
js:1905:9
at Server.Base._callHandler (C:\meanproject\node_modules\mongoose\node_modul
es\mongodb\lib\mongodb\connection\base.js:453:41)
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\con
nection\server.js:488:18
at MongoReply.parseBody (C:\meanproject\node_modules\mongoose\node_modules\m
ongodb\lib\mongodb\responses\mongo_reply.js:68:5)
at null.<anonymous> (C:\meanproject\node_modules\mongoose\node_modules\mongo
db\lib\mongodb\connection\server.js:446:20)
at emit (events.js:107:17)
at null.<anonymous> (C:\meanproject\node_modules\mongoose\node_modules\mongo
db\lib\mongodb\connection\connection_pool.js:207:13)
at emit (events.js:110:17)
at Socket.<anonymous> (C:\meanproject\node_modules\mongoose\node_modules\mon
godb\lib\mongodb\connection\connection.js:440:22)
[nodemon] app crashed - waiting for file changes before starting...
How would I go about solving this?
You need to run the mongodb.exe file first. After successfully starting mongodb, you need to navigate into your project folder and run 'grunt'. If it shows you a error list of modules not found, you need to install those modules globally with npm. That will solve the problem for you. However, please note that bossable.com tutorial is for 0.3 mean stack boiler plate. They have upgraded their version to 0.4.1 now. Follow the Meanjs documentation
for latest information.
I managed to setup nodeclipse with nodemon and I can now start my server.js script with monitor (nodemon) but something strance occurs:
On file change (even on the server.js) nodemon wont restart
In nodeclipse console I dont see the normal nodemon output, ex:
1 Aug 15:20:05 - [nodemon] v1.2.1
1 Aug 15:20:05 - [nodemon] to restart at any time, enter `rs`
1 Aug 15:20:05 - [nodemon] watching: *.*
1 Aug 15:20:05 - [nodemon] starting `node server.js`
PS: I' ve setup monitor path to nodemon.js which is installed with -g parameter
also I can not create any type of run configuration for "Node with monitor"
Is there any way to autorestart the server in nodeclipse even without nodemon if there isn't any other option...
After some time I ended up creating a Node application run configuration and simply added in the arguments tab -> Node arguments the path of nodemon.js
In my case : C:\Users\syd\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js
Now I'm able to get console feed as well stop the node server from eclipse and auto restart on file changes :)