Terminal: Not a directory issue

So the path to my file is: /Users/jasonhunter/Documents/backendCode/script.js

But no matter how I try to navigate there I get the same error: bash: cd: /Users/jasonhunter/Documents/backendCode/script.js: Not a directory

I’ve tried the whole path as well as changing directory’s one by one then ls (listing) the files in backendCode folder. I Googled it several times but couldn’t find any useful solutions. Here is a sample of my code, I left a space between each command. Any help would be appreciated!

Jasons-Air:~ jasonhunter$ pwd
/Users/jasonhunter

Jasons-Air:~ jasonhunter$ cd /Users/jasonhunter/Documents/backendCode/script.js
bash: cd: /Users/jasonhunter/Documents/backendCode/script.js: Not a directory

Jasons-Air:~ jasonhunter$ cd Documents

Jasons-Air:Documents jasonhunter$ cd backendCode

Jasons-Air:backendCode jasonhunter$ ls
Hello.js        app.js          finally.js      script.js

Jasons-Air:backendCode jasonhunter$ cd script.js
bash: cd: script.js: Not a directory

Presumably, the names Hello.js, app.js, finally.js, and script.js are all filenames that contain JavaScript source code. As the message said, they aren’t directories, so you can’t use cd to navigate into them.

What is your goal? Are you trying to run the JavaScript files? If so, once you get to the directory that you ran ls in to see all the files, you could try to use node script.js. This will work if you have node installed and it’s in your path.

2 Likes

Thank you, that made complete sense and was embarrassingly simple! Worked perfectly.

2 Likes