Node JS Error: ENOENT

前端 未结 6 1467
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: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
    

提交回复
热议问题