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

arthurakay picture arthurakay · Apr 7, 2015 · Viewed 14.5k times · Source

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.

Answer

Jakub Bejnarowicz picture Jakub Bejnarowicz · Feb 1, 2016

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