javascript - NPM nodemon 和 debug 在终端中没有输出

标签 javascript node.js terminal output

我有这个简单的代码:

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/

相关文章:

javascript - 将带有回调的约定 node.js 函数转换为生成器并产生

javascript - 在异步循环后写入控制台

node.js - 通过 Node.Js 生成的管道 Amazon S3 下载流导致下载不完整

javascript - 为什么 req.cookies 未定义?

c - C程序的奇怪打印 - Linux终端

delphi - 如何从服务器检查 exe 是否在终端 session 上运行

javascript - 文本输入将错误值插入列表项

javascript - 如何通过 mouseover/mouseout 在 <div> 附近显示/隐藏新的 <div>?

javascript - 逐步发出 ajax 请求

linux - 为什么 linux 联机帮助页程序不清除终端