Hello,
I followed the instructions in the docs, and I have websokcet and app (version 3.2) running on port 3333. After npm run serve:dev everything works well. However, if my code has an error, then the app crashes and it never restarts. It gets stuck with the message I am including below here, and the only way so far I found out of it is to exit, lsof -i tcp:3333, kill the node processes, and again run npm run serve:dev. I am repeating this loop every other minute as of now. It's very annoying and makes development a pain, please help!
Node version: v6.9.2
Npm version: 3.10.8
Error message:
info adonis:framework +0ms serving app on localhost:3333
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE 127.0.0.1:3333
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1259:14)
at listen (net.js:1295:10)
at net.js:1405:9
at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:81:10)
[nodemon] app crashed - waiting for file changes before starting...
Hey @alaghband ! 馃憢
As the error say, the address 127.0.0. 1 with the port 3333 is already used by some process, try to change the port into your .env file or find which process use them!
Thanks. I tried that, but still same issue keeps appearing. The process that occupies the port is node itself, initiated by adonisjs. The problem seems to be that on restart the port is not freed up and hence the error
May you try to update npm?
$ npm i -g npm
Then try again and display the output of npm run serve:dev.
Sure! Here it is: Following the previous suggestion, I changed port to 3000. Then I successfully ran npm i -g npm. Then:
npm run serve:dev
[email protected] serve:dev /Users/R/Documents/Projects/Node/Adonis-Apps/test-app
nodemon --watch app --watch bootstrap --watch config --watch .env -x node server.js
[nodemon] 1.11.0
[nodemon] to restart at any time, enter rs
[nodemon] watching: /Users/R/Documents/Projects/Node/Adonis-Apps/test-app/app//* /Users/R/Documents/Projects/Node/Adonis-Apps/test-app/bootstrap//* /Users/R/Documents/Projects/Node/Adonis-Apps/test-app/config/*/ .env
[nodemon] starting node server.js
info adonis:framework +0ms serving app on localhost:3000
[nodemon] restarting due to changes...
[nodemon] starting node server.js
/Users/R/Documents/Projects/Node/Adonis-Apps/test-app/app/Model/User.js:29
const seated = room.seats().where(');
^
ParseError: Unterminated string constant
at /Users/R/Documents/Projects/Node/Adonis-Apps/test-app/app/Ws/socket.js (/Users/R/Documents/Projects/Node/Adonis-Apps/test-app/app/Ws/socket.js:1:1)
[nodemon] clean exit - waiting for changes before restart
[nodemon] restarting due to changes...
[nodemon] starting node server.js
info adonis:framework +0ms serving app on localhost:3000
[nodemon] restarting due to changes...
[nodemon] starting node server.js
info adonis:framework +0ms serving app on localhost:3000
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE 127.0.0.1:3000
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1259:14)
at listen (net.js:1295:10)
at net.js:1405:9
at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:81:10)
[nodemon] app crashed - waiting for file changes before starting...
You have an error in your code.
/Users/R/Documents/Projects/Node/Adonis-Apps/test-app/app/Model/User.js:29
const seated = room.seats().where(');
but it seems that there's another problem.
Any idea @thetutlage?
Yes there is an exception thrown due to syntax error and since you are running adonis via nodemon, it keeps the port busy and expect you to fix the error
@RomainLanz I understand I have an error, it was intentional so I could produce an error log and share with you. But isn't having errors part of development process anyway?
@thetutlage "it keeps the port busy and expect you to fix the error" Even after fixing the syntax error it won't get back to life, it's simply stuck there forever until I exit and restart.
I have been using Laravel for years, and that's why I got initially interested in Adonisjs. I have never seen Laravel get stuck because of such errors in my code. It's always ready for my changes! As of now, with adonisjs, what I have to do is to find the processes running on the port, kill them, and restart. And worst part is I have to do it every 2 minutes - I am spending more time on finding, killing, and restarting than the actual development!!! I am sure it does not have to be that way and you guys do it differently. Please do share what I have to do differently to not get stuck with occupied ports while doing development and naturally having errors along the way. Thanks a ton!
///////////////////////
This is what happens after fixing errors (essentially now that error is fixed it's complaining about port being occupied and I have found no way out of this other than exit and restart)
[nodemon] restarting due to changes...
[nodemon] starting node server.js
info adonis:framework +0ms serving app on localhost:3000
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE 127.0.0.1:3000
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1259:14)
at listen (net.js:1295:10)
at net.js:1405:9
at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:81:10)
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting node server.js
info adonis:framework +0ms serving app on localhost:3000
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE 127.0.0.1:3000
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1259:14)
at listen (net.js:1295:10)
at net.js:1405:9
at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:81:10)
[nodemon] app crashed - waiting for file changes before starting...
Nodejs doesn't work the way Php works, I suggest understanding the merits of Nodejs over php first and then try to use Adonisjs or any other framework
Comparing apples to oranges will not help much
The very last line says [nodemon] app crashed - waiting for file changes before starting...
Which means it's waiting for u to fix the error and port is still in use
Thanks. Error was fixed but it doesn't seem to open up the port even after the fix.
@alaghband Okay let's do it together from scratch, without using nodemon.
npm run serve to run the app, this doesn't makes use of nodemon and will start the server normally.// ENGINEERING A SYNTAX ERROR BY CHANGING "IF" TO "F" AND:
npm run serve
[email protected] serve /Users/R/Documents/Projects/Node/Adonis-Apps/test-app
node server.js
/Users/R/Documents/Projects/Node/Adonis-Apps/test-app/app/Model/User.js:40
f (seat.user_id === null) {
^
ParseError: Unexpected token
at /Users/R/Documents/Projects/Node/Adonis-Apps/test-app/app/Ws/socket.js (/Users/R/Documents/Projects/Node/Adonis-Apps/test-app/app/Ws/socket.js:1:1)
// APP CRASHED. NEXT, FIXED THE INTENTIONAL SYNTAX ERROR AND:
npm run serve
[email protected] serve /Users/R/Documents/Projects/Node/Adonis-Apps/test-app
node server.js
info adonis:framework +0ms serving app on localhost:3000
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE 127.0.0.1:3000
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Server._listen2 (net.js:1259:14)
at listen (net.js:1295:10)
at net.js:1405:9
at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:81:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] serve: node server.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/R/.npm/_logs/2017-07-05T15_54_02_159Z-debug.log
What is annoying is that a code works perfectly fine, then you make a simple syntax error like above and it correctly crashes, but when you put the code back to its original working state it still crashes.
Can u share the nodejs and npm version and the operating system you are on?
Sure:
macOS Sierra Version 10.12.3
node -v
v6.9.2
npm -v
5.0.4
P.S. I found a silly workaround: whenever I get stuck with occupied ports, I add a semicolon at the end of one of my variable declarations, and "usually" it puts the app back up and running, and next time I get stuck again with occupied ports I remove that semicolon and again it "usually" works!
I am fresher at nodejs and was just building a basic project. I used nodemon, at first it worked perfectly but after few minutes it showed up this error in gitbash.
*Error: *
JASH PATEL@JASH MINGW64 /c/projects/nodekb
$ nodemon
[nodemon] 1.17.2
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node app.js
C:\projects\nodekb\app.js:18
{
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
[nodemon] app crashed - waiting for file changes before starting...
I've made an app.js file, whose contents are shown below...
*app.js : *
const express = require('express');
const path = require('path');
//init app
const app = express();
//load view engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
//home route
app.get('/', function(req, res) {
let articles = [
{
id:1,
title:'article one',
body:'this is article one'
}
{
id:2,
title:'article two',
body:'this is article two'
}
{
id:3,
title:'article three',
body:'this is article three'
}
];
res.render('index', {
title:'Article',
articles: articles
});
});
//Add Routes
app.get('/articles/add', function(req, res) {
res.render('add_article', {
title:'Add Article'
});
});
//start server
app.listen(3000, function() {
console.log('server started on port 3000...!');
});
Please help me get out of this, I got stuck in this problem since one week.
Thank you in advance
Hey @fingil! 馃憢
You are using express this isn't related to Adonis at all.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Hey @alaghband ! 馃憢
As the error say, the address
127.0.0. 1with the port3333is already used by some process, try to change the port into your.envfile or find which process use them!