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!
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.
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
I'm trying to replicate this, but still getting the logging.
Two important questions:
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"}
Answering your questions:
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] startingnode 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...
Your simple example doesn't have any logging in it...
In the example I have written:
console.log('Server running at http://127.0.0.1:8888/');
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...
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.
What version of node.js are you running? This was just filed
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?
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!
Exactly, that was the reason. I have downloaded the nodejs v0.10.1 and it has worked perfectly.
Thank you very much!
Also going to push a change that fixes logging for 0.6.x.
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
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.
@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.
can i use nodemon and foever together.. I used it but imnot able to see console.log
Most helpful comment
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.