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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:43:00+00:00 2026-06-14T20:43:00+00:00

This seems to me like a pretty basic question, but I haven’t been able

  • 0

This seems to me like a pretty basic question, but I haven’t been able to find an answer.

I’m using express with ejs as template engine and the following dir structure:

 |-static
 |---css
 |---img
 |---js
 |-views

I have static routing defined for static folder:

app.configure(function(){
        app.set('views', __dirname + '/views');
        app.set('view engine', 'ejs');
        app.use(express.bodyParser());
        app.use(partials());
        app.use(express.methodOverride());
        app.use(express.static(__dirname + '/static'));
        app.use(app.router);
        app.enable("jsonp callback");
    });

In Views folder i keep all of my ejs files – one layout.ejs and the rest are files with the actual content of the specific page.

I’ve defined the following routes:

app.get('/', function(req,res){
    locals.date = new Date().toLocaleDateString();
    res.render('home.ejs', locals);
});

app.get('/about', function(req,res){
    locals.date = new Date().toLocaleDateString();
    res.render('about.ejs', locals);
});
app.get('/contact', function(req,res){
    locals.date = new Date().toLocaleDateString();
    res.render('contact.ejs', locals);
});

which takes layout.ejs and renders it with the page together.

Obviously I don’t want to add a new route each time I add a new page, I want it to be done automatically.

So I am guessing it should have to do with defining another app.use(express.static(__dirname + '/views')); ? also I don’t want the url to show /about.ejs but to show /about

Can someone please point me in the right direction ?

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-14T20:43:01+00:00Added an answer on June 14, 2026 at 8:43 pm

    You can write your own routing logic, for example

    function customRouter (req, res, next)
    {
        var locals = {};
        var controllerName = req.params.controllerName;
        res.render(controllerName + '.ejs', locals);
    }
    
    app.get('/:controllerName', customRouter);
    

    This is a simple example however it should give you the trick. You can modify it according to your own needs.

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

Sidebar

Related Questions

This seems like a pretty basic thing to do but although I've been using
This seems like a pretty basic question but I unfortunately don't know the answer
This seems like a repeated question but i'm not able to get my answer.
This seems like the simplest Git question, but I can't find ANYTHING on it.
This seems like quite a silly basic question but it seems something I have
This is a pretty basic question, but I've been working at it for a
This seems like it should be pretty straight forward, but I'm apparently confused. I
This feels like it should be pretty simple, but not much seems to be
This seems like such a simple issue but I cannot find an elegant solution.
This may seem like a basic/stupid/obviously-answered question, but I wanted to check: why use

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.