我有这个简单的代码:
const express = require('express');
const chalk = require('chalk');
const debug = require('debug');
const morgan = require('morgan');
const path = require('path');
const app = express();
const port = process.env.PORT || 3000;
app.use(morgan('tiny'));
app.use(express.static(path.join(__dirname, '/public')));
app.use('/css', express.static(path.join(__dirname, '/node_modules/bootstrap/dist/css')));
app.use('/js', express.static(path.join(__dirname, '/node_modules/bootstrap/dist/js')));
app.use('/js', express.static(path.join(__dirname, '/node_modules/jquery/dist')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/views/index.html'));
});
app.listen(port, () => {
debug(`listening on port ${chalk.green(port)}`);
});
问题是,无论我做什么,启动应用程序监听端口 4000
的输出都不会出现,但其余部分都可以,一切正常。它应该 100% 有效,也许你可以帮助我。谢谢!
最佳答案
根据文档和您的应用程序,这里是您的应用程序的精简示例、修改和输出。
文档:https://www.npmjs.com/package/debug
您的应用(经过精简并稍作修改)- 注意添加了某物
。这就是调试所附加的内容
const express = require('express');
const chalk = require('chalk');
const debug = require('debug')('something');
const app = express();
const port = process.env.PORT || 3004;
debug('some debug statement');
app.listen(port, () => {
debug(`listening on port ${chalk.green(port)}`);
});
来自终端线路的调用:
$ DEBUG=something node ~/path_to_your_project/project_name/app.js
输出:
Chriss-MBP-3:untitled1 lcsharp$ DEBUG=某 Node
~/WebstormProjects/untitled1/app.js
something some debug statement +0ms
something listening on port 3004 +9ms
关于javascript - NPM nodemon 和 debug 在终端中没有输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52679975/