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 trialAlexander Traykov
5,990 PointsI get an error when I try to run the node command in the console
I get this error:
module.js:549
throw err;
^
Error: Cannot find module '/home/treehouse/workspace/Pet.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
When I try to run the node Pet.js
command in the console.
7 Answers
Ari Misha
19,323 PointsHiya there! This error is popping probably 'coz you're not in the same directory in cmd/shell as Pet.js. Just get to the same level as Pet.js and run node pet
and you're good to go if its a node/express file.
I hope it helped!
~ Ari
Teron Bullock
Courses Plus Student 23,672 PointsI'm having the same problem, how do I get to the same level?
Devan Govender
3,002 PointsAri is correct.
Check your current directory in the console. If you type ls
in the console and it returns workspace
, then change to directory '/home/treehouse/workspace/' by typing cd workspace
in the console.
Teron Bullock
Courses Plus Student 23,672 PointsGuys thank you for the help. Devan that did the trick, I had to change the directory.
Tim Furnish
8,593 PointsIn my Visual Code Studio Editor terminal I have navigated to the same directory as the Pet.js file and am trying to run node (node Pet.js), which I already installed, but I'm getting no response. Not even an error. Why would this be happening?
MacBook-Pro-Ubik:Video 5 timfur$ cd /Users/timfur/CodeLouisville/Javascript\ React/02_Object_Oriented_Javascript/stage3/Video\ 5
I am expecting:
Pet { animal: 'dog', age: 1, breed: 'pug' }
Any help appreciated.
Austin Johnson
11,447 PointsIt looks like the command you are executing in the terminal is simply changing the directory to the location of your Javascript file. You need to actually execute that file using node.
Assuming your file is named Pet.js, and is in your "Video 5" folder, run the command -
node Pet.js
Teron Bullock
Courses Plus Student 23,672 PointsAustin I had a lot of trouble with this one as well. In your case I'm not sure why it isn't working but Devan Govender was spot on for me.
Good luck, if you figure it out please share I would love to know what it was.
Aiman Zakaria
9,267 PointsAlexander Traykov, you got that error because you did not save the file before running it.
Liz Laffitte
23,691 PointsI kept getting the error:
Syntax Error: missing ) after argument
Turns out I was missing a comma when I was declaring my variable:
const ernie = new Pet('dog', 1 'pug');
//Should have been
const ernie = new Pet('dog', 1, 'pug');
Jimmy Dorvilus
Full Stack JavaScript Techdegree Graduate 27,972 PointsJimmy Dorvilus
Full Stack JavaScript Techdegree Graduate 27,972 PointsAlexander Zakharov you are getting this error because there is some type of mistake in your js file. For example- the code below gave me a similar error because I typed "mew" instead of "new". hope this help.