Getting started with Express - Error: Cannot find module './routes'

Posted by Enrico Tuttobene on Stack Overflow See other posts from Stack Overflow or by Enrico Tuttobene
Published on 2012-09-09T09:34:04Z Indexed on 2012/09/09 9:37 UTC
Read the original article Hit count: 456

Filed under:
|
|

I am just getting started in the world of Node.JS, and I tried using the command line "express" command to install a basic application (with jade support)

Now, I was playing around with it a bit to see how it works and I am coming across a strange error:

In the /routes directory there is a file called index which contains

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

that, as you all know, renders the index page.

Well, all I did was renaming that file from index.js to router.js, so that I can easily refer to it as I would like to have more than just an index page.

The renaming doesn't work, I get the error

Error: Cannot find module './routes'

Which is weird, as I though that

var express = require('express'),
    routes  = require('./routes');

would require ALL the files in the directory.

There must be something small there I'm missing, and please bare with me as I am pretty new to this.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about node.js

Related posts about express