如何访问文件,它是Nodejs上两个目录? [英] How to access a file, which is 2 directories above on Nodejs?
本文介绍了如何访问文件,它是Nodejs上两个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下文件夹结构:
I have this folder structure:
当前,我正在处理 scripts 文件夹中的 app.js 脚本,并且正在尝试读取 users.csv 文件,该文件位于 replicate_to_mysql 文件夹中.到目前为止,这是我尝试过的:
Currently I am working on the app.js script in the folder scripts and I am trying to read the users.csv file which lives inside the replicate_to_mysql folder. This is what I have tried so far:
var fs = require('fs');
var path = require("path")
var user = fs.readFileSync(path.join('replicate_to_mysql', '../../..', 'user.csv')).toString();
但是这会引发以下错误:
However this throws the following error:
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: '..\\..\\generatedb.sql'
有人知道我如何在node.js中实现这样的目标吗?提前非常感谢
Does anyone know how I could achieve sth like this in node.js? Many thanks in advance
推荐答案
const fs = require("fs");
const filename = "./replicate_to_mysql/user.csv";
const user = fs.readFileSync(filename);
console.log(data)
这篇关于如何访问文件,它是Nodejs上两个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文