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 7722457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:10:47+00:00 2026-06-01T04:10:47+00:00

I am trying to set up a basic node.js server and am getting an

  • 0

I am trying to set up a basic node.js server and am getting an error I cannot figure out. I have 4 files: index.js, server.js, router.js, requestHandlers.js

index.js

var server = require("./server");
var router = require("./router");
var requestHandlers = ("./requestHandlers");

var handle =  {}
handle["/"] = requestHandlers.start;
handle["/start"] = requestHandlers.start;
handle["/upload"] = requestHandlers.upload;

server.start(router.route, handle);

server.js

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

function start(route, handle) {
  function onRequest(request, response) {
    var pathname = url.parse(request.url).pathname;
    console.log("Request for " + pathname + " received"); // 2nd log-- works fine

    route(handle, pathname);

    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.write('Hello World');
    response.end();
  }

  http.createServer(onRequest).listen(8888);
  console.log("Server has started."); //1st log -- works fine

};
exports.start = start;

router.js

function route(handle, pathname) {
    console.log("About to route a request for " + pathname); //3rd log -- works fine
    console.log(handle); // THIS IS THE PROBLEM returns ---> { '/': undefined, '/start': undefined, '/upload': undefined }
    console.log(pathname); //works fine -- returns "/"
    console.log(typeof handle[pathname]); //undefined
    if (typeof handle[pathname] === 'function') {
        handle[pathname](); //never called because above evaluates to undefined
    }
    else {
        console.log("No request handler found for " + pathname);
    }
}

exports.route = route;

requestHandlers.js //code never gets here

function start () {
    console.log("Request handler 'start' was called")
}

function upload () {
    console.log("Request handler 'upload' was called")
}

exports.start = start;
exports.upload = upload;

I have gone over this 100 times and feel pretty confident about what it’s doing, so hopefully there is just some small thing I am missing. thanks!

  • 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-01T04:10:49+00:00Added an answer on June 1, 2026 at 4:10 am

    I think you accidentally forgot the verb (require).

    var requestHandlers = require("./requestHandlers");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Overlooking something basic here but I am trying to set a variable and have
I am trying to set up a basic Silverlight application to run behind the
I am trying to set up a pretty basic messaging system with ActiveMQ. I
I am trying to set up a basic Facebook application using PHP and an
So I am trying to set up a basic timer but I am failing
I'm trying to set up a pretty basic hover animation in jQuery. Mouse over
Mission I'm trying to find out the count of children in a set of
I'm learning more about PHP/Javascript, trying to set up a basic website. I've got
I'm trying to script a very basic set of keystrokes in excel where I'm
I am trying to set up git on my Debian server. However, I'm going

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.