![](/img/trans.png)
[英]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.