DJG DJG - 14 days ago 5x
Javascript Question

Why isn't my node app logging to the terminal or the Chrome console?

I'm a noob when it comes to back-end with Node.

I'm running this file on an Ubuntu 14 server in the cloud. The file is being run with pm2. (ex. pm2 start newServer). The outputs from the console.log()s aren't appearing either in the terminal I've ssh'd into or in the javascript console in the browser. How can I get the file to log output into the terminal I've ssh'd into? Or am I going about this the wrong way entirely (do I need to start learning unit testing, is there some logging module I should be using, ...?)

EDIT: The pm2 logs (viewed with 'pm2 logs' or 'pm2 logs [app name]) don't contain any of the output from the console.log statements in the node script.

EDIT2: I also don't get log output anywhere when I stop the pm2 process and just run the file with node.

result of running with node

EDIT3: Still no output when I run the script with node on my local machine and access the page in the browser via localhost:8080.

FINAL EDIT: Figured it out. It's because my gulpfile had strip-debug in it. Being new to build systems, I didn't realize that said option removed console.logs. I found out by using node-inspector to actually look at the node code that was being run, and finding that my console.log statements had been replaced with "void 0"s.

var express = require('express'); //Require express for middleware use
const app = express();
var http = require('http').createServer(app);
var io = require('')(http); //IO is the server

var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');

app.use(express.static(__dirname + "/served")); //Serve static files

app.get('/', function(req, res){


io.on('connection', function(socket){
// socket.on('chat message', function(msg){
// io.emit('chat message', msg);
// });
console.log("A user connected: ",;

http.listen(8080, function(){
console.log('listening on *:8080');


var url = 'mongodb://localhost:27017/test';
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log("Connected correctly to server.");


I'm not an expert on pm2, but from a quick glance it's designed for production use, and won't log anything to the terminal.

Looking at the page

There is a section on Log facilities which tells you how to look at the logs, with a command like this

pm2 logs APP-NAME       # Display APP-NAME logs

Otherwise if you really just want to see what it is doing, just run your code with node, eg

node myprogram.js