【问题标题】:What does app.listen look like when using npm start使用 npm start 时 app.listen 是什么样的
【发布时间】:2018-05-25 17:20:12
【问题描述】:

这就是我在导出app 变量之前所做的事情,这样我就可以为node/express 应用程序执行unit and integration testing

app.js

//app.listen(3000, () => console.log('Example app listening on port 3000!'))

module.exports = app;

现在

我现在如何启动服务器?我试图将其移动到

中的package.json 文件
"scripts": {"start": "app.listen(3000, () => console.log('Example app listening on port 3000!')" }

所以我可以这样做:

npm start

但它不起作用。

【问题讨论】:

    标签: node.js express mocha.js chai supertest


    【解决方案1】:

    那是行不通的。您可以有一个index.js 来启动您的应用程序,如下所示:

    index.js

    import app from './app'
    
    app.listen(3000, () => console.log('Example app listening on port 3000!'))
    

    你的脚本开始应该是:

    "scripts": {"start": "node index.js" }
    

    这样,您可以在测试中使用您的模块app,您的应用程序将正常工作。

    现在,只需运行:

    npm start
    

    如果您不想进行单元和集成测试,请查看以下链接:

    【讨论】:

      猜你喜欢
      • 2020-02-24
      • 2017-04-08
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      • 2016-12-14
      • 2014-11-17
      • 1970-01-01
      • 2016-05-07
      相关资源
      最近更新 更多