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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:07:07+00:00 2026-05-30T22:07:07+00:00

I am a newbie in Node.js (and Express) and I am trying to make

  • 0

I am a newbie in Node.js (and Express) and I am trying to make sense of this. Say I have a website with 3 pages (can be GET or POST): /, /page1, /page2. What should I do so that every page is handled by a separate JS file?

app.all('/', function(request, response)
{
    // Get home.js to handle this request and response
});
app.all('/page1', function(request, response)
{
    // Get page1.js to handle this request and response
});
app.all('/page2', function(request, response)
{
    // Get page2.js to handle this request and response
});

Better yet, is there a way to define a wildcard so there is not so much repetition? Something like this:

app.all('*', function(request, response)
{
    // Get *.js to handle this request and response. * is whatever the URI string is
});
  • 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-05-30T22:07:08+00:00Added an answer on May 30, 2026 at 10:07 pm

    Continuing my discussion with @Alex. Here’s how I did it. Any gotcha?

    // app.js
    var EXPRESS = require('express');
    var URL = require('url');
    var PATH = require('path');
    
    var app = EXPRESS.createServer();
    
    app.all(/^\/([a-zA-Z0-9-]+)$/, function(request, response, next)
    {
        var page = request.params[0];
        if (PATH.existsSync(__dirname + '/' + page + '.js'))
        {
            require('./' + page).handleRequest(request, response, next);
        }
        else
        {
            next();
        }
    });
    
    app.all('*', function(request, response)
    {
        response.send('Catch all');
    });
    
    // --- truncated for brievity
    
    
    // page1.js
    exports.handleRequest = function(request, response, next)
    {
        response.send('Howdy!');
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm newbie about node.js and mongodb. I have already installed mongodb, but I can't
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I am newbie to LINQ. I am trying to read the following node and
newbie here .. wondering why in the table i get something called '[object node]'
I'm an XML newbie and I have an XML document (which I can't edit
i'm a total newbie to java and Alfresco and i have this simple problem:
I want to make in a TreeView (winforms) that each node will have in
I am a newbie to the Node.js, Mongoose and Expressjs. I have tried to
Complete C# newbie here, so cut me some slack. I have this application that
Newbie Warning I have a simple but vexing problem trying to disable an NSButton.

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.