Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 715
arthurakay Avatar asked Apr 07 '15 16:04

arthurakay


People also ask

How do I see console log in terminal?

Enable view of the Terminal and Debug Console (go to the View menu and select Terminal). You can press F5 for Debugging or Ctrl-F5 for Run without debugging. When you get a menu asking for environment, select Node. js.

Is console log () added to execution stack?

console. log('Inside Global Execution Context'); An Execution Context Stack for the above code. When the above code loads in the browser, the Javascript engine creates a global execution context and pushes it to the current execution stack.

How do I get the console log back?

console. log() is a function used to print information to the console. return on the other hand is a call to pass some value back up to where the call was made. For instance, let's say you create a function called square() that takes in a single numeric parameter and returns that value squared.


2 Answers

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

like image 133
Jakub Bejnarowicz Avatar answered Sep 28 '22 09:09

Jakub Bejnarowicz


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.

like image 43
viktor_vangel Avatar answered Sep 28 '22 08:09

viktor_vangel