I am coming across the below error when I try running the node js script I have written
$ node script1.js
module.js:338
throw err;
^
Error: Cannot find module '/Users/dir1/dir2/script1.js'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:124:16)
at node.js:811:3
Is there something I am missing on including?
The error you are getting indicates that your script1.js
file is not where you think it is. Here's an example of what happens if I run Node on a non-existent file:
$ node non-existent
module.js:340
throw err;
^
Error: Cannot find module '/tmp/non-existent'
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
Find out where your file is and provide node with the right path.
Figured that it is a bad character issue in the case of this script. Re-typing the script helped resolve the issue.