1

I'm new to node.js and javascript. I install node.js successfully,but when I run the js file in terminal on mac,I got error.

han:~ cuibosoft$ node example.js 

module.js:340
    throw err;
          ^
Error: Cannot find module '/Users/cuibosoft/example.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

I'm sure example.js is at /Users/cuibosoft/. I don't know why node can't it.

3
  • That's rather odd. Can cat find it? (cat example.js) Commented Jun 7, 2014 at 5:43
  • node start /Users/cubiosoft/example.js or while you are in correct directory, node start example.js Commented Jun 7, 2014 at 5:43
  • @icktoofay No, it also doesn't work. Commented Jun 7, 2014 at 5:48

1 Answer 1

1

You might think it is, but judging from your comment, example.js cannot be in /Users/cuibosoft. If it's on your desktop, then it's really in /Users/cuibosoft/Desktop. If you want to move it to your home directory proper, you can open your home directory in Finder by pressing ⌘⇧H.

Sign up to request clarification or add additional context in comments.

4 Comments

But when I run ls, example.js is showed in terminal.
Now I add a file "example.txt" to the same dictionary, and run cat example.txt, and it works well.
@nimingzhe2008: Maybe it's got a space in the filename somewhere. You could try using tab completion, typing e.g. node ex<TAB> and letting your shell try to complete it for you.
Thank you very much. I change the file name to some.js, and it works well now. So strange.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.