Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:48:54+00:00 2026-06-11T18:48:54+00:00

I have created a nodejs http server var http = require(http); var url =

  • 0

I have created a nodejs http server

var http = require("http");
var url = require("url");
var express = require('express');
var app = express();

function start(route, handle){
    function onRequest(request,response){
        var pathname = url.parse(request.url).pathname;
        console.log("Request for " + pathname + " received.");
        route(handle, pathname, response, request);
    }

    http.createServer(onRequest).listen(8888);
    console.log("Server has started");
    app.listen(8888);
    console.log('Express app listening on port 8888');
}

it gives error

f:\Labs\nodejs\webapp>node index.js
Server has started
Express app listening on port 8888

events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: listen EADDRINUSE
    at errnoException (net.js:769:11)
    at Server._listen2 (net.js:909:14)
    at listen (net.js:936:10)
    at Server.listen (net.js:985:5)
    at Function.app.listen (f:\Labs\nodejs\webapp\node_modules\express\lib\appli
cation.js:532:24)
    at Object.start (f:\Labs\nodejs\webapp\server.js:15:6)
    at Object.<anonymous> (f:\Labs\nodejs\webapp\index.js:11:8)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)

when i change the port of app.listen it dont throw this error, what can be done?

will changing port other than server port will keep the session of the server on another port??

and how can i access this app variable in other js page to get/set the data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:48:55+00:00Added an answer on June 11, 2026 at 6:48 pm

    You can’t have multiple things listening on the same port like this, hence the EADDRINUSE error. If you want to create your own http server while using Express, you can do it like this:

    var express = require('express');
    var https = require('https');
    var http = require('http');
    var app = express();
    
    http.createServer(app).listen(8888);
    https.createServer(options, app).listen(443);
    

    From the Express docs:

    The app returned by express() is in fact a JavaScript Function,
    designed to be passed to node’s http servers as a callback to handle
    requests.

    Or you can just do

    app.listen(8888);
    

    And then Express will setup an http server for you.

    You would then set up your routes in Express to actually handle requests coming in. With Express, routes look like this:

    app.get('/foo/:fooId', function(req, res, next) {
       // get foo and then render a template
       res.render('foo.html', foo);
    });
    

    If you want to access your app in other modules (usually for testing) you can just export it like any other variable:

    module.exports.app = app;
    

    You’ll then be able to require('./app').app in other modules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read that a HTTP server created in node.js does not create new
I have a module I created for a node.js app. The app also uses
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I have created this jsfiddle: http://jsfiddle.net/mfnxm/1/ I am trying to create this JSON: [{
Given code like this from a node.js neophyte like me: require('http').createServer(function( req, resp )
I have setup myself a NodeJS and socket.io server with the mysql node module
I have a NodeJS TCP socket server running and I'd like to add support
I have worked on NodeJs and Redis before. Since NodeJs is a web server
I have 3 home PCs that have 2008 SQL Server Express instances installed on
I have created a small server for communication using node.js and socket io Server:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.