console.log() does not appear in my terminal (nwjs)


In my nwjs app, I load a _launch.js file from an HTML file:

<html>
<body>
<script type="text/javascript" src="_launch.js"></script>
</body>
</html>

And in my _launch.js file, I fire up the the Node processes I need for an express server and socketIO.

var express = require('express'),
    app = express(),
    server = require('http').Server(app),
    io = require('socket.io')(server),
    gui = require('nw.gui'),

    __curDir = process.cwd(),

    //keep the logic for the IO connections separate
    ioServer = require(__curDir + '/server.js');

//configure Express to default web requests to /workspace/ folder
app.use(express.static(__curDir + '/workspace'));

ioServer.init(io, console);

server.listen(3000, function () {
    console.log('HTTP server listening on *:3000');
    window.location = 'http://localhost:3000/MyApp/';
});

The app launches just fine, and my express/socketIO connections are all perfectly working.

But while the console.log() in the server.listen() callback appears in my terminal, any messages I try to log from the server.js file (required earlier) never show up anywhere.

Any ideas why?

Per the nwjs wiki, any files loaded via require() should be running in the Node context (and mine otherwise appears to be) -- but for whatever reason, I cannot use console.log() to view logged information.

Please look at the list of changes related to node in the nw.js wiki.

Since node-webkit supports GUI applications instead of console applications, the output of console.log() (and other similar methods such as console.warn() and console.error()) is redirected to WebKit's console. You may see it in your “Developer Tools” window (on its “Console” tab).


You have to run DevTools for Background Page by right clicking on your app and choosing the Inspect background page option from the context menu.

Inspect background page
click for full size image

Here is a related bug report: 0.13-beta3 console.log doesn't work in node context


Just pass --enable-logging=stderr in chromium-args in your package.json:

{
    ...
    "chromium-args": "--enable-logging=stderr",
    ...
}

Or use the Inspect background page DevTools as @Jakub Bejnarowicz has pointed out.