在写入文件之前如何触摸文件?
试图
fs = require 'fs'
os = require 'os'
path = require 'path'
json_filepath = path.join os.tempdir(), 'cache', 'foo.json'
module.exports = (cb) ->
fs.open json_filepath, 'w', 438, (err) -> # Touch, also tried with node-touch
return cb err if err?
fs.writeFile json_filepath, {foo: 'bar'}, {}, (err) ->
#console.error 'Error writing cache: ', err
cb err
错误
{ [Error: ENOENT, open '/tmp/cache/foo.json']
errno: 34,
code: 'ENOENT',
path: '/tmp/cache/foo.json' }
这是一个 POSIX 错误(linux 手册页,另外为 Windows 实现,例如:在 libuv 中)。这意味着:没有这样的文件或目录