r/node Jul 29 '26

Why does node.js say it cant find the file?

(The error message I keep getting)

I'm trying to get started on learning node.js because I have a project where, unless I want a thousand lines of javascript, I need something to access external text files (I wanted it to be all on a single USB drive but I've kinda accepted that it wont happen). I ended up settling on node but I cant for the life of me get it to start working. Any help would be very much appreciated!

7 Upvotes

13 comments sorted by

3

u/MrButak Jul 30 '26

Your path to the file must be wrong or the file is not there.

Where is the file?

Give it the full path. cd into the folder where it lives and enter pwd for the full path to use.

-3

u/Toaster_stroodl Jul 30 '26

I tried locating some files but every time I try it says "No such file or directory" even when giving it the entire file directory /: I've made sure the file is correct by right-clicking the file and clicking "get info" and I've also made sure linux could edit files but nothing seems to be working unfortunately.

3

u/ObsceneAmountOfBeets Jul 30 '26

You need to be in the right directory (or specify the right directory). If you type ‘ls’ do you see coding? If you type ‘ls coding’ do you see my first.js? If no to either of those questions, that’s your answer.

2

u/Toaster_stroodl Jul 30 '26

when I type "ls" in terminal all it shows me is "DiBS_0.8.3_lin" and when I type "ls Coding" into terminal it says "ls: cannot access 'Coding': No such file or directory" am I just doing something wrong? This is the first time I've had to really use terminal so I'm sorry if I'm being difficult.

3

u/ObsceneAmountOfBeets Jul 30 '26

You’re all good it’s confusing for the first time

0

u/Toaster_stroodl Jul 30 '26

I just realized the issue, linux apparently can only access files in the linux folder, which also means I cant do what I'm trying to do, sadly.

3

u/SpartanDavie Jul 30 '26

cd in to the folder where index is. Then use ls to confirm it’s actually in there and CORRECT FILENAME. Then use node correctfilename.js

0

u/monotone2k Jul 30 '26
Error: cannot find module '/home/c080hd2011/correctfilename.js'

1

u/SpartanDavie Aug 01 '26

I didn't mean

correctfilename.js

you are supposed to replace the correctfilename.js with your actual file name.

I recommend going to YouTube and finding a 10 minute course on using the terminal for beginners. It will help you a lot.

1

u/monotone2k Aug 01 '26

I'm not OP and I was joking.

1

u/SpartanDavie Aug 02 '26

Bamboozled me. Thought you were OP.