我的项目结构是这样的
现在,我需要将 asset.js 中的文件写入 pdf 文件夹中的文件。
这就是我正在尝试的
var qrImgPath = '/lib/pdf/' +eod+'.png';
fs.writeFile(qrImgPath,body,'binary',function(err){
return next();
});
但我收到以下错误
{ handle: 2,
type: 'error',
className: 'Error',
constructorFunction: { ref: 5 },
protoObject: { ref: 6 },
prototypeObject: { ref: 1 },
properties:
[ { name: 'stack',
attributes: 2,
propertyType: 3,
ref: 1 },
{ name: 'arguments',
attributes: 2,
propertyType: 1,
ref: 1 },
{ name: 'type',
attributes: 2,
propertyType: 1,
ref: 1 },
{ name: 'message',
attributes: 2,
propertyType: 1,
ref: 7 },
{ name: 'errno',
propertyType: 1,
ref: 8 },
{ name: 'code',
propertyType: 1,
ref: 9 },
{ name: 'path',
propertyType: 1,
ref: 10 } ],
text: 'Error: ENOENT, open \'/lib/pdf/b0551796a741aa885e641dbd895a233f.png\'' }
.
我怎样才能实现这个目标?
最佳答案
您可以使用__dirname
。 (https://nodejs.org/docs/latest/api/globals.html#globals_dirname)
path.join(__dirname, "../../lib/pdf" + eod + "png");
关于javascript - 将文件写入与工作目录不同的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36738371/