javascript - Nodemon not reloading page - Stack Overflow

I am starting studying Node.js, so I am using nodemon to reload my page, but it's not working and

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745148961a4613776.html

相关推荐

  • javascript - Nodemon not reloading page - Stack Overflow

    I am starting studying Node.js, so I am using nodemon to reload my page, but it's not working and

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信