Ask coding questions

← Back to all posts
This error keeps happening, ive tried tons of ports that should work, anybody that can help me?
xXJohnDoeXx (2)

throw er; // Unhandled 'error' event

Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle as _listen2
at listenInCluster (net.js:1364:12)
at Server.listen (net.js:1450:7)
at /home/runner/Node-stuff-test/index.js:18:8
at Script.runInContext (vm.js:130:18)
at Object.<anonymous> (/run_dir/interp.js:209:20)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1343:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 3000

Answered by RowanFromBJC (46) [earned 5 cycles]
View Answer
RowanFromBJC (46)

use express

const fs = require('fs'); // File System (To read files)
const express = require('express'); // Express (Server module)
var app = express(); // App (Server)
app.get('/', (req, res) => { // When someone goes to (The / means when someone requests /. If someone requests /projects, then you would want to do the same thing, but instead use /projects and projects.html)
  res.set('Content-Type', 'text/html'); // Set the MIME type (
  res.send(fs.readFileSync('index.html', 'utf8')); // Read the contents of index.html and send it

app.listen(8080, () => { // Listen on port 8080 (Dunno why, but for some reason I always use it)
  console.log('Server up and running!'); // You should see this if it works
xXJohnDoeXx (2)

i got something working with just http [email protected]


@xXJohnDoeXx why where u not on yesterday

xXJohnDoeXx (2)

Earlier I put on port 4000, it worked for a few minutes, then stopped, when I ran again it did the exact same error as port 3000

EpicGamer007 (1615)

can you attach the repl please?

xXJohnDoeXx (2)

@EpicGamer007 Im gonna make my portfolio on it but currently I am testing it, I don't do node.js a ton, I used a tutorial for the server.

xXJohnDoeXx (2)

wait i just found an error i made before lemme see if fixing it does anything @EpicGamer007

EpicGamer007 (1615)

@xXJohnDoeXx why are you using the http module? use express. it is much simpler and cleaner.

xXJohnDoeXx (2)

@EpicGamer007 ima just make a new server and use whole new tutorial