简体   繁体   中英

Route file failing to update in Express.js

I am new to using both Node and Express.

Express.js looked great, so I created a local deployment of a vanilla install.

Visiting http://localhost:3000/users prints the expected message:

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:

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. 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 will run your application in the form it was when initially started, until that process is terminated.

The most common way to address this is by using a process manager, the most popular one used during development is nodemon . To use nodemon , install it globally on your machine using npm i -g nodemon (you'll probably need admin rights to do this). Then, run your application using nodemon instead of node .

nodemon <path/to/main>.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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