I have been using a Windows 10 laptop for years and now I changed to a MacBook. I pulled some of my code from Github (using exactly the same code for my server) and Nodemon doesn't want to restart the server automatically when I hit save. What's going on?
index.js:
const express = require("express");
const path = require("path");
const cors = require("cors");
const bodyParser = require("body-parser");
const http = require("http");
const app = express();
const server = http.createServer(app);
app.use(express.json({ extended: false, limit: "5mb" }));
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
app.get("*", (req, res) =>
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"))
);
}
const PORT = process.env.PORT || 3001;
server.listen(PORT, () => console.log(`Server started on port ${PORT}.`));
I make some changes then hit save then I get this error:
events.js:292
[0] throw er; // Unhandled 'error' event
[0] ^
[0]
[0] Error: listen EADDRINUSE: address already in use :::3001
Package.json:
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
What I want is that when I hit save, it saves everthing then restarts the server on the same port. Everything is automatic. I do not want to kill the server manually each time I save. This one worked on Windows 10 and now it doesn't on my MacBook...