最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Nodemon not reloading page - Stack Overflow

programmeradmin1浏览0评论

I am starting studying Node.js, so I am using nodemon to reload my page, but it's not working and already tried all Stack solutions aswell.

Look how simple is my code:

package.json

{
  "name": "api",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.4"
  },
  "devDependencies": {
    "nodemon": "^1.18.3"
  }
}

server.js

const express = require('express');

const app = express();

app.get('/', (req, res) => {
  res.send('Hey');
});

app.listen(3001);

My bash while interacting with res.send() message.

I am starting studying Node.js, so I am using nodemon to reload my page, but it's not working and already tried all Stack solutions aswell.

Look how simple is my code:

package.json

{
  "name": "api",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.4"
  },
  "devDependencies": {
    "nodemon": "^1.18.3"
  }
}

server.js

const express = require('express');

const app = express();

app.get('/', (req, res) => {
  res.send('Hey');
});

app.listen(3001);

My bash while interacting with res.send() message.

Share Improve this question asked Apr 23, 2019 at 22:49 jvbsjvbs 4463 gold badges14 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You are using nodemon with the server. It is restarting the server as you make changes to the server.js file. That is, your endpoints are being updated. This will not cause your client to reload. As you are simply navigating to the endpoint that you are creating within the browser, you will not see the changes reflected without refreshing.

That isn't to say that there is no benefit to running nodemon in this way. If you were not doing so you would need to also close the node instance (ctrl-c) and then rerun it every time before refreshing the page. Otherwise, you would still be running the old version of your server and still see the same content served.

Eventually you will consume these endpoints using an http client from your client application, this is generally when you take advantage of a hot reloading environment. There are some options here if you want to make express live-reload before then.

发布评论

评论列表(0)

  1. 暂无评论