Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a Simple Dynamic Site with Node.js Handling Routes in Node.js User Route

faraz
PLUS
faraz
Courses Plus Student 21,474 Points

Error: Cannot find module './router.js'

Getting this error even though router.js is present and included as instructed:

throw err;
^
Error: Cannot find module './router.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/treehouse/workspace/app.js:1:76)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)

Workspace snapshot: https://w.trhou.se/1auokn19pe

1 Answer

@faraz Something seems to be wrong with the file name, not the code (the router file being placed above app.js in the file tree is a clue). I got it to work by renaming the router.js file to "router.js".

faraz
faraz
Courses Plus Student 21,474 Points

Ah yes looks like I had an extra space before the file name. Removing that did the trick, thanks!