0

I cant see console.log() messages from rest functions.

http.listen(port, ip, function(){
console.log('Express server started on port %s', http.address().port);});

Within http.listen(), i can see the logs as expected, but when i call other rest functions, like:

app.get('/aaa', function (req, res, next) {
res.send('hello world');
console.log('hello')});

it is not writing any logs, but it does return "hello world".

when i run it locally on my pc i can see the logs, but when i deploy it the problem starts again. i also tried to to write logs with the "fs" api, but it still does not work.

any idea why res.send() does work but console.log() does not?

devops
  • 13
  • 1
  • 5
  • How do you start your server when you deploy your code ? It gets outputted somewhere, you probably just don't have access to stdout of that process – edi9999 Sep 18 '15 at 15:40
  • 1
    put `console.log` before res.send... res.send must be the last statement in your handler functions.... –  Sep 18 '15 at 16:46
  • That isn't true. See http://stackoverflow.com/questions/16180502/node-express-why-can-i-execute-code-after-res-send – Dan D. Sep 18 '15 at 17:25
  • The problem has to do with where it is being deployed. But you have told us nothing about that nor have you given a [mcve] – Dan D. Sep 18 '15 at 17:27

2 Answers2

0

app.listen instead of http.listen fixed it.

devops
  • 13
  • 1
  • 5
0

You can try to put the console.log(...) before res.send. I think res.send() is the end destination of request then process escape after this.

thelonglqd
  • 1,805
  • 16
  • 28