Search code examples
javascriptnode.jserror-handlingdiscord.jsunhandled

why is there an unhandled 'error' event in javascript


I have the following error and I would like to know why it is there and/or how to remove it:

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

Error: listen EADDRINUSE: address already in use :::8080
    at Server.setupListenHandle [as _listen2] (net.js:1279:14)
    at listenInCluster (net.js:1327:12)
    at Server.listen (net.js:1414:7)
    at Object.<anonymous> (/home/runner/keep_alive.js:6:4)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
Emitted 'error' event at:
    at emitErrorNT (net.js:1306:8)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

The link to my (long) code is here: https://repl.it/@HungryIronApple/HungryIronEntertainment at first, this was an unexpected input end error which I have fixed. After taking my time to fix the error, I ran into this more confusing error take your time to reply since the before error code is still up and running


Solution

  • Error: listen EADDRINUSE: address already in use :::8080
    

    Your script is attempting to listen to port 8080 for connections to but another process is already using it. Kill that other process, or reassign that process or yours to another port (and configure them accordingly if one listens to the other). It's probably another local development server from another script of yours.

    It's also common practice for a script to try another port if the default is taken. For instance, if the default port of your app is 8080 but it's taken, you could try 8081, or 8082, and so on.