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

In my nwjs application, I am loading the _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 run the Node processes needed for 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 application starts up fine and my express / socketIO connections work great.

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

Any ideas why?

On the wiki nwjs wiki, any files downloaded using require () must be executed in the context of Node (and, it seems to me, otherwise) - but for some reason I cannot use console.log () to view the log information .

+6
source share
3 answers

Check out the list of changes related to node in the wiki version of nw.js.

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 the WebKit console. You can see it in the "Developer Tools" window (on the "Console" tab).

+8
source

You need to launch DevTools for the background page by right-clicking on your application and selecting the Inspect background page option in the context menu.

Inspect background page
click for full size image

Here is the related error report: 0.13-beta3 console.log not working in node context

+19
source

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

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

Or use the Inspect background page DevTools like @Jakub Bejnarowicz .

+8
source

Source: https://habr.com/ru/post/984801/


All Articles