S
S
svilkov872018-11-27 18:22:03
Node.js
svilkov87, 2018-11-27 18:22:03

Node/Express swears on a port?

Hello.
After npm run buildDev , as well as npm start error:

> node ./dist/server.js

events.js:182
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::8080
    at Object._errnoException (util.js:1041:11)
    at _exceptionWithHostPort (util.js:1064:20)
    at Server.setupListenHandle [as _listen2] (net.js:1322:14)
    at listenInCluster (net.js:1370:12)
    at Server.listen (net.js:1466:7)
    at Function.listen (/home/vilkov/projects/aleton-express-webpack-1/node_modules/express/lib/application.js:618:24)
    at eval (webpack:///./src/server/server-dev.js?:48:5)
    at Object../src/server/server-dev.js (/home/vilkov/projects/aleton-express-webpack-1/dist/server.js:97:1)
    at __webpack_require__ (/home/vilkov/projects/aleton-express-webpack-1/dist/server.js:20:30)
    at /home/vilkov/projects/aleton-express-webpack-1/dist/server.js:84:18
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! aleton-express-webpack-1@1.0.0 start: `node ./dist/server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the aleton-express-webpack-1@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vilkov/.npm/_logs/2018-11-27T13_26_35_680Z-debug.log

package.json:
"scripts": {
    "test": "jest",
    "coverage": "jest --coverage",
    "buildDev": "rm -rf dist && webpack --mode development --config webpack.server.config.js && webpack --mode development --config webpack.dev.config.js",
    "buildProd": "rm -rf dist && webpack --mode production --config webpack.server.config.js && webpack --mode production --config webpack.prod.config.js",
    "start": "node ./dist/server.js"
  },

server.js:
import path from 'path'
import express from 'express'
const app = express(),
    DIST_DIR = __dirname,
    HTML_FILE = path.join(DIST_DIR, 'index.html')
app.use(express.static(DIST_DIR))
app.get('*', (req, res) => {
    res.sendFile(HTML_FILE)
})
const PORT = process.env.PORT || 8080
app.listen(PORT, () => {
    console.log(`App listening to ${PORT}....`)
    console.log('Press Ctrl+C to quit.')
})

I have to watch every time what the port is doing:
sudo lsof -i :8080
and every time bang it, then calling again b> npm run buildDev and npm start
sudo kill -9 pid
Can I somehow fix this so that when restarting there are no errors associated with the port?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksei Podgaev, 2018-12-10
@alexiusp

So what is the port busy with every time? Maybe you can not run that second server during development?
Set the default to some port that is probably not busy, for example 3000, 4000. Or set it in the environment variables for your project, if possible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question