[英]Why isn't the following expect … toThrowError logging anything in my terminal?
[英]Why isn't my node app logging to the terminal or the Chrome console?
对于Node的后端,我是一个菜鸟。
我正在云中的Ubuntu 14服务器上运行此文件。 该文件正在使用pm2运行。 (例如,pm2启动newServer)。 console.log()的输出既不会出现在我所连接的终端中,也不会出现在浏览器的JavaScript控制台中。 如何获取文件以将输出记录到我已登录的终端中? 还是我完全以错误的方式解决了这个问题(我是否需要开始学习单元测试,是否应该使用某些日志记录模块,...?)
编辑:pm2日志(使用“ pm2日志”或“ pm2日志[应用程序名称]查看”)不包含节点脚本中console.log语句的任何输出。
EDIT2:当我停止pm2进程并仅使用node运行文件时,我也不会在任何地方获得日志输出。
EDIT3:当我在本地计算机上运行带有节点的脚本并通过localhost:8080访问浏览器中的页面时,仍然没有输出。
最终编辑:弄清楚了。 这是因为我的gulpfile中包含了带调试功能。 作为构建系统的新手,我没有意识到该选项删除了console.logs。 我发现通过使用node-inspector来实际查看正在运行的节点代码,并发现我的console.log语句已被替换为“ void 0”。
var express = require('express'); //Require express for middleware use
const app = express();
var http = require('http').createServer(app);
var io = require('socket.io')(http); //IO is the server
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
//BASICS
app.use(express.static(__dirname + "/served")); //Serve static files
app.get('/', function(req, res){
res.sendFile('./index.html');
});
io.on('connection', function(socket){
// socket.on('chat message', function(msg){
// io.emit('chat message', msg);
// });
console.log("A user connected: ", socket.id);
});
http.listen(8080, function(){
console.log('listening on *:8080');
});
console.log('test')
// MONGODB
var url = 'mongodb://localhost:27017/test';
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log("Connected correctly to server.");
db.close();
});
我不是pm2方面的专家,但是从一眼看,它是为生产使用而设计的,不会在终端上记录任何内容。
看页面
https://github.com/Unitech/pm2
有一个关于日志功能的部分,它告诉您如何使用这样的命令查看日志
pm2 logs APP-NAME # Display APP-NAME logs
否则,如果您真的只想看看它在做什么,则只需使用node运行代码,例如
node myprogram.js
使用pm2
模块时,日志按每个单独的节点保存。 为了查看它们,您可以发出命令pm2 logs
来查看每个节点的日志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.