console.log() 没有出现在我的终端 (nwjs)
console.log() does not appear in my terminal (nwjs)
在我的 nwjs 应用程序中,我从 HTML 文件加载 _launch.js 文件:
<html>
<body>
<script type="text/javascript" src="_launch.js"></script>
</body>
</html>
在我的 _launch.js 文件中,我启动了 Express 服务器和 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/';
});
应用程序启动正常,我的 express/socketIO 连接都正常工作。
但是当 server.listen() 回调中的 console.log() 出现在我的终端时,我尝试从 server.js 文件(之前需要)永远不会出现在任何地方。
知道为什么吗?
根据 nwjs wiki,通过 require() 加载的任何文件在节点上下文中都应该是 运行(否则我的似乎是)——但是对于无论出于何种原因,我都无法使用 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).
您必须通过右键单击您的应用并从上下文菜单中选择 检查背景页面 选项来 运行 DevTools for Background Page。
这是一个相关的错误报告:0.13-beta3 console.log doesn't work in node context
只需在 package.json 的 chromium-args
中传递 --enable-logging=stderr
:
{
...
"chromium-args": "--enable-logging=stderr",
...
}
或者使用 Inspect background page
DevTools,正如 指出的那样。
在我的 nwjs 应用程序中,我从 HTML 文件加载 _launch.js 文件:
<html>
<body>
<script type="text/javascript" src="_launch.js"></script>
</body>
</html>
在我的 _launch.js 文件中,我启动了 Express 服务器和 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/';
});
应用程序启动正常,我的 express/socketIO 连接都正常工作。
但是当 server.listen() 回调中的 console.log() 出现在我的终端时,我尝试从 server.js 文件(之前需要)永远不会出现在任何地方。
知道为什么吗?
根据 nwjs wiki,通过 require() 加载的任何文件在节点上下文中都应该是 运行(否则我的似乎是)——但是对于无论出于何种原因,我都无法使用 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).
您必须通过右键单击您的应用并从上下文菜单中选择 检查背景页面 选项来 运行 DevTools for Background Page。
这是一个相关的错误报告:0.13-beta3 console.log doesn't work in node context
只需在 package.json 的 chromium-args
中传递 --enable-logging=stderr
:
{
...
"chromium-args": "--enable-logging=stderr",
...
}
或者使用 Inspect background page
DevTools,正如