Node JS Error: ENOENT

前端 未结 6 1458
Happy的楠姐
Happy的楠姐 2020-12-05 01:27

I\'m following along with: The Node Beginner Book

After testing with the code from another SO post:

var Fs = require(\'fs\');

var dirs = [\'tmp\'];         


        
相关标签:
6条回答
  • 2020-12-05 02:07

    use "temp" in lieu of "tmp"

    "/temp/test.png"

    it worked for me after i realized the tmp is a temporary folder that didn't exist on my computer, but my temp was my temporary folder

    ///

    EDIT:

    I also created a new folder "tmp" in my C: drive and everything worked perfectly. The book may have missed mentioning that small step

    check out http://webchat.freenode.net/?channels=node.js to chat with some of the node.js community

    0 讨论(0)
  • 2020-12-05 02:10

    if your tmp folder is relative to the directory where your code is running remove the / in front of /tmp.

    So you just have tmp/test.jpg in your code. This worked for me in a similar situation.

    0 讨论(0)
  • 2020-12-05 02:12

    You can include a different jade file into your template, that to from a different directory

    views/
         layout.jade
    static/
         page.jade
    

    To include the layout file from views dir to static/page.jade

    page.jade

    extends ../views/layout
    
    0 讨论(0)
  • 2020-12-05 02:17

    change

    "/tmp/test.jpg".
    

    to

    "./tmp/test.jpg"
    
    0 讨论(0)
  • 2020-12-05 02:20

    "/tmp/test.jpg" is not the correct path – this path starts with / which is the root directory.

    In unix, the shortcut to the current directory is .

    Try this "./tmp/test.jpg"

    0 讨论(0)
  • 2020-12-05 02:28

    To expand a bit on why the error happened: A forward slash at the beginning of a path means "start from the root of the filesystem, and look for the given path". No forward slash means "start from the current working directory, and look for the given path".

    The path

    /tmp/test.jpg
    

    thus translates to looking for the file test.jpg in the tmp folder at the root of the filesystem (e.g. c:\ on windows, / on *nix), instead of the webapp folder. Adding a period (.) in front of the path explicitly changes this to read "start from the current working directory", but is basically the same as leaving the forward slash out completely.

    ./tmp/test.jpg = tmp/test.jpg
    
    0 讨论(0)
提交回复
热议问题