草庐IT

javascript - Nodemon - 安装期间为 "clean exit - waiting for changes before restart"

coder 2024-07-24 原文

我正在尝试使用 Node 和 Postgres 设置 RESTful API。我遇到了一个问题,每当我尝试运行服务器(使用 npm start)在本地测试它时,我都会得到以下输出:

[nodemon] 1.14.10 [nodemon] to restart at any time, enter rs [nodemon] watching: . [nodemon] starting node index.js server.js [nodemon] clean exit - waiting for changes before restart

在网上搜索了一段时间后,我找不到太多关于“干净退出 - 重启前等待更改”的确切含义的资源,尤其是在这种情况下。

这是我的 queries.js 文件:

  1 var promise = require('bluebird');
  2 
  3 var options = {
  4   // Initialization Options
  5   promiseLib: promise
  6 };
  7 
  8 // created an instance of pg-promise, override default pgp lib w bluebird
  9 var pgp = require('pg-promise')(options);
 10 var connectionString = 'postgres://localhost:3000/actions';
 11 var db = pgp(connectionString);
 12 
 13 // add query functions
 14 
 15 module.exports = {
 16   getAllActions: getAllActions,
 17 //  getSingleAction: getSingleAction,
 18 //  createAction: createAction,
 19 //  updateAction: updateAction,
 20 //  removeAction: removeAction
 21 };
 22 
 23 function getAllActions(req, res, next) {
 24   db.any('select * from acts')
 25     .then(function (data) {
 26       res.status(200)
 27         .json({
 28           status: 'success',
 29           data: data,
 30           message: 'Retrieved ALL actions'
 31         });
 32     })
 33     .catch(function (err) {
 34       return next(err);
 35     });
 36 }

这是我的 index.js 文件:

  3 var express = require('express');
  4 var app = express();
  5 var router = express.Router();
  6 var db = require('./queries');
  7 
  8 // structure: expressInstance.httpRequestMethod(PATH, HANDLER)
  9 app.get('/api/actions', db.getAllActions);
 10 //app.get('/api/actions/:id', db.getSingleAction);
 11 //app.post('/api/actions', db.createAction);
 12 //app.put('/api/actions/:id', db.updateAction);
 13 //app.delete('/api/actions/:id', db.removeAction);
 14 
 15 module.exports = router;

对这里可能发生的事情有什么想法吗?提前致谢。

最佳答案

您的代码有一些问题。你从来没有告诉你的应用程序运行。当你准备好创建你的路线时,你应该启动你的服务器:

app.listen(<port on which the server should run here>);

您在同一个文件中还有一个 Express 应用程序和一个路由器。路由器应该只用作子模块(当你想将你的应用程序划分为多个文件时很方便)。现在你什么都不做。如果您删除路由器和导出,那么它应该可以正常工作。

关于javascript - Nodemon - 安装期间为 "clean exit - waiting for changes before restart",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48534555/

有关javascript - Nodemon - 安装期间为 "clean exit - waiting for changes before restart"的更多相关文章

随机推荐