0

I have a software to get attached file from specific email real time. It had made by node js. It works well window 7. Here is Directory structure.

  • > --- myfolder

    |
    -- node_modules (<code>imap</code>,<code>mime</code>,<code>fs</code>,<code>ftp</code> ......) 
    -- run.bat
    -- uploadCSV.js</li>
    

For MacOS, I have made run.command file instead of run.bat file.

Content of run.bat  ---  node upload.CSV

Content of run.command --- #!/bin/bash

                       node uploadCSV.js

When I installed nodejs in MacOS and double click run.command, some error comes up like below.


Last login: Fri Jan 16 10:19:23 on ttys000
Mimis-Mac-mini:~ mimi$ /Users/mimi/Documents/app/run.command ; exit;
module.js:340
    throw err;
          ^
'rror: Cannot find module '/Users/mimi/uploadCSV.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:929(cat)
logout

I don't know well about shell script for MacOS. Help me ! Why can I fix this error? Thanks, Tomi

1
  • Your "require" statement seems to be looking for an "absolute" path. It needs to be relative to the application install. Commented Jan 16, 2015 at 7:02

1 Answer 1

1

It has to do with your current working directory. You're executing "node uploadCSV.js" from your user's home directory. Node is trying to load uploadCSV.js from /Users/mimi. This is why you get the error "Cannot find module /Users/mimi/uploadCSV.js".

You can fix it by simply cd-ing (change directory) into the folder with the node file.

$ cd /Users/mimi/Documents/app/
$ ./run.command

You could also change run.command to contain the full path of the node script:

node /Users/mimi/Documents/app/uploadCSV.js
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help. "Cannot find module" error has been fixed.
By the way I have found new errors. stackoverflow.com/questions/27984954/… can you help me? Thanks.

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.