在我的 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/';
});
该应用程序启动正常,我的 express/socketIO 连接都运行良好。
但是当 server.listen() 回调中的 console.log() 出现在我的终端时,我尝试从 server.js 文件记录的任何消息(之前需要)永远不会出现在任何地方。
有什么想法吗?
根据 nwjs wiki,通过 require() 加载的任何文件都应该在 Node 上下文中运行(否则我的似乎是)——但无论出于何种原因,我都不能使用 console.log() 查看记录的信息。
最佳答案
您必须通过右键单击您的应用并从上下文菜单中选择检查后台页面选项来运行 DevTools for Background Page。
这是一个相关的错误报告:0.13-beta3 console.log doesn't work in node context
关于javascript - console.log() 没有出现在我的终端 (nwjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29496847/