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
Kyle Knapp21,526 Points
Cannot find module node.js
Workspace snapshot: https://w.trhou.se/lzs4xyte5q
node _misc/tests/requireTest.js in the console returns
Cannot find module '../requireMe.js'
I have also tried require('./requireMe.js') and require('requireMe.js') with the same error.
Is it not possible to require a module from a parent folder? Or is the path name wrong?
Your code path needs to move up a few directories in order to find the requireMe.js file.
const foo = require('../../requireMe.js');
There is an npm module that will do this.
// get the application's root directory
var appRootDir = require('app-root-dir').get();
// set the application's root directory
// (this will set a global so that no matter
// how many instances of app-root-dir module are
// installed, they will all return the same