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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:39:02+00:00 2026-06-11T12:39:02+00:00

I’m quite new to node.js, and pretty new to Javascript (I don’t count simple

  • 0

I’m quite new to node.js, and pretty new to Javascript (I don’t count simple animations with jQuery as js). As a web-developer, I’m moving from PHP/MySQL to Express/mongo.

I like the idea of things being neat – as long as there isn’t a noticeable loss in performance. As node is so rapidly developing, I’m finding it hard to find specific opinions and answers to my routeing methods for the current version of node (Most posts I find seem to be irrelevant and older than 2 years).

|- app.js
    |- routes
        |- blog.js

I’m using blog.js as the gateway for all blog-related stuff. This includes registering GET and POST requests with a function, and handling page-rendering.

This is all fired up with one call.

My app.js has the following:

... //basic express installation
var db = ... //mongoose database connection

require('./routes/blog')(app, db, '/blog'); //starts the blog up

blog.js looks like this:

var db = null;
var basedir = null;

module.exports = function(app, _db, _basedir){
  db = _db;
  basedir = _basedir;

  app.get (basedir, pages.home );
  app.get (basedir + '/show/:id', pages.getBlog );

  /*app.get(basedir + '/*', function(req, res) {
    res.redirect(basedir);
  });*/ 
};

var pages = {
      home : function(req, res) {
        // whatever
    }

    , getBlog : function(req, res) {
        // whatever
    }
}

I know this works – my question, is if this is conventional? Is it something that isn’t recommended? Is it memory-wasteful? Why do people place app.gets in app.js rather than an external file? What are the current mainly used routeing methods (I develop multiple small applications all on the same server, hence my wish for my app.js to be as minimal as possible).

  • 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-11T12:39:03+00:00Added an answer on June 11, 2026 at 12:39 pm

    The way you’ve outlined is perfectly acceptable, and in my mind, preferred to just having one big app.js file with all your routes and everything else in it.

    Many people take the separating of code much further than what you’ve outlined, especially when trying to follow MVC and MVC-like patterns.

    For example, here’s a boilerplate project I’d been working on that might even go a little overboard on separation. It’s not a finished product, just something I was playing with that took some of the different bits I liked from other boilerplates, frameworks, etc. I’ve learned some things since then and I might adjust it at some point.

    NemoJS – My node/express/mongoose/jade/stylus/twitter_bstrap boilerplate project

    One thing to keep in mind is the more you separate it, the more difficult it CAN be to track down problems. Not a good enough reason for not staying organized though. Which is essentially what our goal is, right?

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.