console.log()没有出现在我的终端(nwjs)中 [英] console.log() does not appear in my terminal (nwjs)

查看:364
本文介绍了console.log()没有出现在我的终端(nwjs)中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的nwjs应用中,我从HTML文件中加载了 _launch.js 文件:

In my nwjs app, I load a _launch.js file from an HTML file:

<html>
<body>
<script type="text/javascript" src="_launch.js"></script>
</body>
</html>

在我的 _launch.js 文件中,我启动了快速服务器和socketIO所需的Node进程.

And in my _launch.js file, I fire up the the Node processes I need for an 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/';
});

该应用程序启动正常,我的express/socketIO连接均正常运行.

The app launches just fine, and my express/socketIO connections are all perfectly working.

但是当server.listen()回调中的 console.log()出现在我的终端上时,我尝试从 server.js 文件记录的所有消息(之前需要)永远不会出现在任何地方.

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

有什么想法吗?

根据nwjs Wiki,通过 require()加载的任何文件都应在Node上下文中运行(否则我的看起来是这样)-但由于任何原因,我不能使用 console.log()查看已记录的信息.

Per the nwjs wiki, any files loaded via require() should be running in the Node context (and mine otherwise appears to be) -- but for whatever reason, I cannot use console.log() to view logged information.

推荐答案

请查看

由于node-webkit支持GUI应用程序而不是控制台应用程序,所以console.log()(以及其他类似方法,例如console.warn()和console.error())的输出将重定向到WebKit的控制台.您可能会在开发人员工具"窗口(位于其控制台"选项卡上)中看到它.

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).

这篇关于console.log()没有出现在我的终端(nwjs)中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆