Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging with nodemon #153

Closed
fuentecilla86 opened this issue Mar 26, 2013 · 17 comments
Closed

Logging with nodemon #153

fuentecilla86 opened this issue Mar 26, 2013 · 17 comments

Comments

@fuentecilla86
Copy link

Hey everyone!

I am using console.log for loggin but it does not work with nodemon. It works when I started the server with node but not with nodemon.

I have been reading that it can be because of the version, but I have the 0.7,3 and it should work. Could anyone help me?

Thanks in advance!

@remy
Copy link
Owner

remy commented Mar 26, 2013

Do you have a simple example that replicates this problem - because I use logging a lot in my projects, and use nodemon nearly exclusively and not heard of this problem before.

Also useful to know what platform you're running on to replicate the issues to help debug it.

Thanks.

@fuentecilla86
Copy link
Author

Thanks for being so fast!

Here you have an example (just proxying a request) and it does not work:

node_test.js


var http = require('http'),
httpProxy = require('http-proxy');
//
// Create your proxy server
//
httpProxy.createServer(9000, 'X.X.X.X').listen(8888);

//
// Create your target server
//
http.createServer(function (req, res) {
console.log('LOGGING');
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);


Here is how it works:

sudo node node_test.js
LOGGING
LOGGING


sudo nodemon node_test.js

26 Mar 10:05:56 - [nodemon] v0.7.3
26 Mar 10:05:56 - [nodemon] watching: XXXX
26 Mar 10:05:56 - [nodemon] starting node node_test.js


The platform is an Ubuntu 12.04.1 LTS

@remy
Copy link
Owner

remy commented Mar 26, 2013

I'm trying to replicate this, but still getting the logging.

Two important questions:

  1. Why are you running nodemon with sudo
  2. How are you testing the logging.

I'm doing: curl -i http://localhost:9000

But looking at the http-proxy, I'm not sure that's the right port.

When I ran the code (without sudo - because without I can still bind both 9000 and 8888) and I curl port 8888 I get:

remy@ubuntu:~$ curl -i http://localhost:8888
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain
Date: Tue, 26 Mar 2013 10:41:03 GMT
Connection: keep-alive
Transfer-Encoding: chunked

An error has occurred: {"code":"ENOTFOUND","errno":"ENOTFOUND","syscall":"getaddrinfo"}

@fuentecilla86
Copy link
Author

Answering your questions:

  1. I'm running nodemon with sudo because it will be in the upstart service. Even not running it with sudo, the logging does not work.
  2. I'm testing it writting "console.log ('LOGGING') in the code and doing a "curl http://localhost:8888".

If you do the curl in the port 8888 it forwards the request to the 9000 port, where the server is listening.

If I run with node, I can see "LOGGING" in the console, but not with nodemon.

I have also tried a more simple example and it still does not work with nodemon:


var http = require('http'),
express = require('express');

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8888);

console.log('Server running at http://127.0.0.1:8888/');


In this example:

For testing:

curl http://localhost:8888
Hello World

Server logging with node:

node node_test2.js
Server running at http://127.0.0.1:8888/

Server loggin with nodemon:

nodemon node_test2.js
26 Mar 12:00:40 - [nodemon] v0.7.3
26 Mar 12:00:40 - [nodemon] watching XXX
26 Mar 12:00:40 - [nodemon] starting node node_test2.js

As you can see, it logs "Server running at http://127.0.0.1:8888/" with node but nothing with nodemon.

I don't know what else I could do...

@remy
Copy link
Owner

remy commented Mar 26, 2013

Your simple example doesn't have any logging in it...

@fuentecilla86
Copy link
Author

In the example I have written:

console.log('Server running at http://127.0.0.1:8888/');

@remy
Copy link
Owner

remy commented Mar 26, 2013

Oh - sorry, I spotted the console.log at the end.

I've just tried the same thing and it's working exactly as expected on ubuntu 12.04.2:

remy@ubuntu:~/nodemon/test/express$ nodemon simple.js
26 Mar 04:14:29 - [nodemon] v0.7.3
26 Mar 04:14:29 - [nodemon] watching: /home/remy/nodemon/test/express
26 Mar 04:14:29 - [nodemon] starting `node simple.js`
Server running at http://127.0.0.1:8888/

I'm not sure what to do next...

@remy
Copy link
Owner

remy commented Mar 26, 2013

Are you able to get the Hello World response when you're running with nodemon?

I'm wondering if in fact it's not even running node and your script.

@remy
Copy link
Owner

remy commented Mar 26, 2013

What version of node.js are you running? This was just filed

@fuentecilla86
Copy link
Author

Yes, the script is working and I get the "Hello Worl".

Maybe you are right and it's the version of the nodejs. I installed from the repository and it is the 0.6.12. Could it be the reason?

@remy
Copy link
Owner

remy commented Mar 26, 2013

I think so, particularly going by #154. Are you able to upgrade?

I'm going to investigate this logging issue on 0.6.x - but I'm not sure I should justify supporting stable-2 versions. I'm conflicted over this!

@fuentecilla86
Copy link
Author

Exactly, that was the reason. I have downloaded the nodejs v0.10.1 and it has worked perfectly.

Thank you very much!

@remy remy closed this as completed Mar 26, 2013
@remy
Copy link
Owner

remy commented Mar 26, 2013

Also going to push a change that fixes logging for 0.6.x.

@nainglinaung
Copy link

I also face with same issue, my code is as follow

var express = require('express');
var path = require('path');
var app = express();

app.set('view engine','jade');
app.set('views', __dirname + '/views');

var db = require('./config')(app,express);
var base_url = path.normalize(__dirname+'/..');
console.log('hi');

app.use('/static', express.static(base_url+'/public/components'));
app.use('/public', express.static(base_url+'/public/custom'));


// seed 
/*
var seeds = require('./server/seeds/seeds');
seeds.set();
*/
// route 

var routes = require('./routes')(app);
var port = process.env.PORT || 8080;

app.listen(port);
console.log('magic happened at'+port);

and nodemon as follows

> nodemon ./server/index.js

23 Jan 18:23:01 - [nodemon] v1.2.1
23 Jan 18:23:01 - [nodemon] to restart at any time, enter `rs`
23 Jan 18:23:01 - [nodemon] watching: *.*
23 Jan 18:23:01 - [nodemon] starting `node ./server/index.js`
23 Jan 18:25:36 - [nodemon] restarting due to changes...
23 Jan 18:25:36 - [nodemon] starting `node ./server/index.js`
23 Jan 18:25:44 - [nodemon] restarting due to changes...
23 Jan 18:25:44 - [nodemon] starting `node ./server/index.js`

I currently working on OSX Yosemite, node verison is 1.0.4

@alanshaw
Copy link

I got the same problem with iojs v1.2.0 and nodemon v1.2.1. Upgrading to nodemon v1.3.7 fixed it for me.

@BenjaminConant
Copy link

@alanshaw thank for the answer ... I also had this issue, for me updating from nodemon 1.2.1 to nodemon 1.3.7 fixed it as well.

@nikitabanthiya
Copy link

can i use nodemon and foever together.. I used it but imnot able to see console.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants