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

  • Home
  • SEARCH
  • 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 8952817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:57:30+00:00 2026-06-15T13:57:30+00:00

I am following along with this article , which describes a good way to

  • 0

I am following along with this article, which describes a good way to organize routes in express. I am encountering a problem though when i try to access the functions that i have exported from my main.js file. I get a 404 error when i curl “localhost/user/username”

//the routes section of my my app.js file
app.get('/', routes.index);
app.get('/user/:username', routes.getUser);

//my index.js file
require('./main');
require('./users');

exports.index = function(req, res) {
    res.render('index', {title: 'Express'});
};

//my main.js file

exports.getUser = function(req, res){
        console.log('this is getUser');
        res.end();
};

—-EDITED WITH MY SOLUTION—-

Here is the solution that I went with, maybe someone will find it useful. I’m also open to hearing suggestions about whether or not this is going to cause me any problems in the future.

//-------The routes in my app.js file now look like this.

require('./routes/index')(app);
require('./routes/main')(app);

//-------In index.js i now have this

module.exports = function(app) {
    app.get('/', function(req,res){
        res.render('index', {title: 'Express'});
    });
};

//-------My main.js now looks like this-------

module.exports = function(app){

    app.get('/user/:username', function(req, res){
            var crawlUser = require('../engine/crawlUser');
            var username = req.params.username;
            crawlUser(username);
            res.end();
    });

};
  • 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-15T13:57:31+00:00Added an answer on June 15, 2026 at 1:57 pm

    Here is the solution that I went with, maybe someone will find it useful.

    //-------The routes in my app.js file now look like this.
    
    require('./routes/index')(app);
    require('./routes/main')(app);
    
    //-------In index.js i now have this
    
    module.exports = function(app) {
        app.get('/', function(req,res){
            res.render('index', {title: 'Express'});
        });
    };
    
    //-------My main.js now looks like this-------
    
    module.exports = function(app){
    
        app.get('/user/:username', function(req, res){
                var crawlUser = require('../engine/crawlUser');
                var username = req.params.username;
                crawlUser(username);
                res.end();
        });
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Hibernate 3.3.1 and am following along in modelling this sample table structure
I have an HTML along the following lines: <div class=hiddenClass> // this implies display:none
I have the following view code which displays events, along with headers informing the
[for those not following along at home, this is the sequel to Rolling My
I am trying to set up a custom entity, following along alan storms article
I am following along this Ruby on Rails tutorial and after following the steps
I am a python/django newbie following along this tutorial on dotcloud . I git
I'm a newbie to programming for iPhone, I'm following along this book. I'm stuck
I am following along with this Django blog tutorial and can not get the
I am following along with the first video in the iTunes U course, and

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.