This is for an app built with Express. One of my concerns is the routes ending with / which I did because our previous site was an ASP app. So they named the folders that way for SEO purposes, then the page would be index.aspx .But in my case I just did, for example

science.jade and routed it from /science-bruxzir-zirconia-dental-crown/

Here is what I got for routes


var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon(path.join(__dirname, 'public/images/template/favicon.ico')));
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {

app.get('/', function(req, res){
  res.render('home', {
    title: 'Home'

app.get('/features-bruxzir-zirconia-dental-crown/', function(req, res){
  res.render('features', {
    title: 'BruxZir Features'

app.get('/science-bruxzir-zirconia-dental-crown/', function(req, res){
  res.render('science', {
    title: 'Scientific Validation'

app.get('/video-bruxzir-zirconia-dental-crown/', function(req, res){
  res.render('videos', {
    title: 'BruxZir Video Gallery'

app.get('/cases-bruxzir-zirconia-dental-crown/', function(req, res){
  res.render('cases', {
    title: 'Before & After Case Gallery'

app.get('/testimonials-bruxzir-zirconia-dental-crown/', function(req, res){
  res.render('testimonials', {
    title: 'Bruxzir Testimonials'

app.get('/authorized-bruxzir-labs-zirconia-dental-crown/', function(req, res){
  res.render('labs', {
    title: 'Authorized BruxZir Labs'

app.get('/contact-bruxzir-zirconia/', function(req, res){
  res.render('contact', {
    title: 'Bruxzir Contact Form'

app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
  • \$\begingroup\$ Looks alright to me, the only thing i would suggest is to brake this file up. What exactly concerns you though? \$\endgroup\$ – GnrlBzik Dec 31 '13 at 6:15
  • \$\begingroup\$ @GnrlBzik the biggest concern is that the route ending in / looks a bit sloppy. But our previous routing used that structure because there was a index.aspx inside that file. But now I am just naming that page that name. I don't know how many sites point into this, so i wanted to preserve that url so we don't lose traffic. Also the routes seem a bit verbose, I would think there is a way to make this more concise. Also wanted tips on how exactly I can break up the project. \$\endgroup\$ – JGallardo Dec 31 '13 at 18:31
  • \$\begingroup\$ well you already using require statements to pull ./routes and ./routes/user why not move out bottom route definitions to separate files, i would also brake set and use into separate config file that you can require, just pass app to that require statement. thats what i would do from code management stand point. \$\endgroup\$ – GnrlBzik Jan 3 '14 at 20:09
  • 1
    \$\begingroup\$ So if you want to move away from those hideous routes, why not use redirect, so that you dont lose them in any way, you could also define regex for routes for each resource to match new route and old. Its up to you, ugly urls, yes, but is that much of an issue for only about 10 urls? \$\endgroup\$ – GnrlBzik Jan 3 '14 at 20:23
  • \$\begingroup\$ I see where you used user.list. Is this route related logic? \$\endgroup\$ – GnrlBzik Jan 3 '14 at 20:25

From a once over of the code and the comments:

  • This code is fine, especially if you have only a dozen routes, I would not advise you to build your own route building infrastructure for such a small amount of routes
  • Dont worry about the /
  • Consider having your routes in separate files as per @GnrlBzik

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.