在我的nwjs应用程序中,我从
HTML文件加载_launch.js文件:
<html> <body> <script type="text/javascript" src="_launch.js"></script> </body> </html>
在我的_launch.js文件中,我启动了快速服务器和socketIO所需的Node进程.
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/'; });
该应用程序启动很好,我的快递/ socketIO连接都完美的工作.
但是当我的终端中出现server.listen()回调中的console.log()时,我尝试从server.js文件(之前需要)记录的任何消息都不会出现在任何地方.
有什么想法吗?
根据nwjs wiki,通过require()加载的任何文件都应该在Node上下文中运行(而且看起来似乎也是如此) – 但无论出于何种原因,我都不能使用console.log()来查看记录的信息.
解决方法
请查看nw.js wiki中的
changes related to node列表.
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).
@H_403_23@