Ex18 (&19) error messages in node


#1

I keep getting this error message:

let ex18 = require(’./ex18’)
{ Error: Cannot find module ‘./ex18’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18) code: ‘MODULE_NOT_FOUND’ }

I have tried typing in the entire file path in node and different file names such as ‘ex18.js’, etc but get the same message.

Please help

Thanks


#2

Double check that you have the ex18.js file in your current directory:

ls ex18.js

If you get an error then you’re in the wrong place. Also, do it like this:

const ex18 = require('./ex18');

It’s a little more common to use const there than let.


#3

Hi Zed,

Thanks for your reply.

It seems I am in the wrong place, but how do I get to the correct directory, I am using a Mac and therefore Terminal

Thanks

Geeta


#4

Welllll, when you save the file you should try to be aware of where it gets saved so you can cd to it. If you have no idea where then enter this command:

find ~/ -name “ex18.js” -print

That might take a while, since it’s searching your whole home directory, but when it’s done it should print out where ex18.js lives. Then cd to that directory. So if it says:

Documents/ex18.js

Then you do:

cd Documents

Also, you should have watched the Ex0 video for MacOSX. I go through how to correctly setup your environment and part of that is creating an ljsthw directory and saving the file in the correct place. If you’re on 18 and still have no idea where things are being saved then I’d say you need to start over as where you save files is a critical part of programming.