This is driving me crazy -- I've tried to make a simple Express app using async/await and it works fine, but when it restarts with nodemon I keep getting EADDRINUSE errors. I'm using node version 11.15, this is running under MacOS.server up and running on port 4321events.js:170throw er; // Unhandled 'error' event ^Error: listen EADDRINUSE: address already in use :::4321 at Server.setupListenHandle [as _listen2] (net.js:1259:14) at listenInCluster (net.js:1307:12) at Server.listen (net.js:1395:7) at Function.listen (/Users/abc/Documents/Projects/sandbox/axa/node_modules/express/lib/application.js:618:24) at listen (/Users/abc/Documents/Projects/sandbox/axa/src/server.js:28:15) at tryCatch (/Users/abc/Documents/Projects/sandbox/axa/node_modules/regenerator-runtime/runtime.js:45:40) at Generator.invoke [as _invoke] (/Users/abc/Documents/Projects/sandbox/axa/node_modules/regenerator-runtime/runtime.js:271:22) at Generator.prototype.(anonymous function) [as next] (/Users/abc/Documents/Projects/sandbox/axa/node_modules/regenerator-runtime/runtime.js:97:21) at asyncGeneratorStep (/Users/abc/Documents/Projects/sandbox/axa/src/server.js:26:103) at _next (/Users/abc/Documents/Projects/sandbox/axa/src/server.js:28:194) at processTicksAndRejections (internal/process/task_queues.js:86:5) Emitted 'error' event at: at emitErrorNT (net.js:1286:8) at processTicksAndRejections (internal/process/task_queues.js:81:17)I've tried to kill the process in numerous locations -- for example in my nodemon.json file I've got kill-port --port 4321 for start, restart and crash. My app starts out by killing the port -- from my package.json:"start": " nodemon --exec 'kill-port --port 4321 & babel-node src/index.js'",And yet, if I type in a file and nodemon restarts the app, I get the EADDRINUSE error. I feel there must be something wrong in my conversion to async/await, but I don't know. My server setup follows -- I get the crash just after app.listen(). What am I doing wrong? Is there something here that is not returning a promise but with which I am using await? How can I address the error? Thanks for any help -- I've spent hours trying to figure this out.mongoose.set('useCreateIndex', true);const {env: { DATABASE_URL, PORT, SERVICE_LOAD_INTERVAL = 600000 }} = process;const server = async () => {try {await mongoose.connect(DATABASE_URL, {useNewUrlParser: true,useUnifiedTopology: true});const app = express();app.use(cors());app.use("/api", routes());await setupDB();taskSetup(setupDB, SERVICE_LOAD_INTERVAL);await app.listen(PORT);console.log(\server up and running on port ${PORT}`); } catch (e) { logger.error(`Server Initialisation Error: ${e.message}`); } };`My package.json file is{"scripts": {"start": " nodemon --exec 'kill-port --port 4321 & babel-node src/index.js'","lint": "eslint \"src/**/*.{js}\" --quiet","test": "echo \"Error: no test specified\" && exit 1"},"dependencies": {"axios": "^0.19.0","body-parser": "^1.19.0","cors": "^2.8.5","dotenv": "^8.1.0","express": "^4.17.1","express-async-handler": "^1.1.4","express-jwt": "^5.3.1","express-jwt-permissions": "^1.3.1","express-session": "^1.16.2","jsonwebtoken": "^8.5.1","kill-port": "^1.5.2","mongodb": "^3.3.2","mongoose": "^5.7.1","winston": "^3.2.1"},"devDependencies": {"@babel/core": "^7.6.0","@babel/node": "^7.6.1","@babel/preset-env": "^7.5.5","@types/express": "^4.17.1","eslint": "^6.2.2","eslint-config-prettier": "^6.1.0","nodemon": "^1.19.2","prettier": "^1.18.2"}}
Submitted September 18, 2019 at 02:11AM by atacamasand
No comments:
Post a Comment