简体   繁体   English

路由文件无法在Express.js中更新

[英]Route file failing to update in Express.js

I am new to using both Node and Express. 我是使用Node和Express的新手。

Express.js looked great, so I created a local deployment of a vanilla install. Express.js看起来很棒,所以我创建了一个vanilla安装的本地部署。

Visiting http://localhost:3000/users prints the expected message: 访问http:// localhost:3000 / users会打印出预期的消息:

respond with a resource

I try changing the text to this instead: 我尝试将文本更改为:

respond with no resource

But the change is not made. 但是没有做出改变。 This is the contents of users.js, almost exactly the same as default: 这是users.js的内容,几乎与默认值完全相同:

var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with no  resource');
});

module.exports = router;

And here is a screenshot. 这是一个截图。 Top left is the above code. 左上角是上面的代码。 Bottom left demonstrates a grep for "respond with a resource" failing to produce any results. 左下角显示了一个grep,用“响应资源”无法产生任何结果。 The right hand side is my browser displaying old data. 右侧是我的浏览器显示旧数据。

What am I doing wrong that the data is not updating ? 我错误的是数据没有更新

Your application will not automatically update if you use node <path/to/main>.js to run your application. 如果使用node <path/to/main>.js来运行应用程序,则应用程序不会自动更新。 node will run your application in the form it was when initially started, until that process is terminated. node将以最初启动时的形式运行您的应用程序,直到该进程终止。

The most common way to address this is by using a process manager, the most popular one used during development is nodemon . 解决此问题的最常见方法是使用流程管理器,开发期间使用的最流行的是nodemon To use nodemon , install it globally on your machine using npm i -g nodemon (you'll probably need admin rights to do this). 要使用nodemon ,请使用npm i -g nodemon在您的计算机上全局安装它(您可能需要管理员权限才能执行此操作)。 Then, run your application using nodemon instead of node . 然后,使用nodemon而不是node来运行应用程序。

nodemon <path/to/main>.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM