angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.12k stars 1.24k forks source link

new project, get undefined as hostname #205

Closed ralyodio closed 10 years ago

ralyodio commented 10 years ago

Express server listening on undefined:9000, in development mode

and app crashes right away when running grunt serve

Running "express:dev" (express) task
Starting background Express server
debugger listening on port 5858
Express server listening on undefined:9000, in development mode

Running "open:server" (open) task

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: failed to connect to [localhost:27017]
    at null.<anonymous> (/Users/user/projects/offsite/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:553:74)
    at EventEmitter.emit (events.js:106:17)
    at null.<anonymous> (/Users/user/projects/offsite/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
    at EventEmitter.emit (events.js:98:17)
    at Socket.<anonymous> (/Users/user/projects/offsite/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:512:10)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:440:14
    at process._tickCallback (node.js:415:13)

Running "watch" task
bogini commented 10 years ago

Make sure you're running MongoDB.

After installing it, run mongod then grunt serve

ralyodio commented 10 years ago

that was it. thanks.

krisalexander200 commented 10 years ago

@ibeitia i built my project without mongo (which I think was a prompt question at the beginning of the generator questions, and i said no to Mongo), because the application requires no database.

I get the undefined error when starting the application. What would be the right way to handle the issue in this scenario?

timmaybrown commented 10 years ago

mongod is running, but no matter what I do I still get this error of:

 Express server listening on undefined:9000, in development mode
Running "serve" task

Running "clean:server" (clean) task
Cleaning .tmp...OK

Running "bower-install:app" (bower-install) task

Running "concurrent:server" (concurrent) task

    Running "compass:server" (compass) task
    directory .tmp/styles/ 
       create .tmp/styles/main.css (0.014s)
    Compilation took 0.014s

    Done, without errors.

    Execution Time (2014-05-21 05:13:28 UTC)
    compass:server  450ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99%
    Total 454ms

Running "autoprefixer:dist" (autoprefixer) task
Prefixed file ".tmp/styles/main.css" created.

Running "express:dev" (express) task
Starting background Express server
debugger listening on port 5858
Express server listening on undefined:9000, in development mode

Running "open:server" (open) task
finished populating things
db connection open
finished populating users

Running "watch" task
Waiting...

This is a brand new project with fresh install of the generator. Not sure what i'm missing here...

zfarrell commented 10 years ago

@chair9design - are you able to access the site (i.e. http://localhost:9000/) once the server starts?

The undefined in Express server listening on undefined:9000, in development mode is a bug, but I believe it's only an issue with this log message, not an issue with starting the server.

Let me know if this assumption is wrong, and we can continue to debug.

timmaybrown commented 10 years ago

adding it to all.js seemed to do the trick for me, but like you said it doesn't seem to be necessary at the same time, because once I got past the undefined:9000 error, the conflict I ran into next was the fact that I also had php-fpm listening on port 9000 which was causing this error... http://stackoverflow.com/questions/16827987/expressjs-throw-er-unhandled-error-event

I found what was running on port 9000 by running this command. sudo lsof -i :9000

Then confirmed nothing was running on 3000 by changing the above command to:

sudo lsof -i :3000

Once I new 3000 was a safe port, I changed the port to 3000 in my grunt file's express options, as well as, the all.js exports definition port: process.env.PORT || 3000,

Now all is well and seeing 'Allo, 'Allo ! ... hopefully this helps someone else out.

timmaybrown commented 10 years ago

see above, but to directly answer your question about the server running despite the error message, the answer was no, but that seems to be primarily because I'm running php-fpm on port 9000 so I can reverse proxy some php sites via NGINX. Once I switched the port the server started up. The console log still says undefined, but the app started up once the port was changed, so your commit seem like it will fix the console.log in the server.js file on app start.

ralyodio commented 10 years ago

In ./config/development.js add this line:

ip: 'localhost'

that should fix the problem.

timmaybrown commented 10 years ago

adding ip: 'localhost' was the first route I went, but that didn't fix the issue only because port 9000 wasn't free since php-fpm was already listening on this port otherwise simply adding the ip property to the ./config/development.js file should have done the trick. But in all actuality, this isn't even needed because the app starts without it, it's just that there is an undefined logged value on app startup in server.js when it's not added to development.js