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 .
source share