美文网首页我爱编程
fs 读不到路径下文件 express

fs 读不到路径下文件 express

作者: Haydn | 来源:发表于2018-04-16 01:01 被阅读0次

https://stackoverflow.com/questions/48469666/error-enoent-no-such-file-or-directory-open-moviedata-json

fs.readFileSync('moviedata.json', 'utf8') will look for moviedata.json in the directory from where you ran your application, not in the directory where your MoviesLoadData.js file is located.

Suppose you ran node aws/MoviesLoadData.js from /Users/dortiz/Documents/NodeJS/pruebas/zw, fs.readFileSync('moviedata.json', 'utf8') would look for moviedata.json in /Users/dortiz/Documents/NodeJS/pruebas/zw, not in /Users/dortiz/Documents/NodeJS/pruebas/zw/aws

If you were to run your script with my given example, you'd need to prepend the path to the json file to correctly reference it.

fs.readFileSync(__dirname + '/moviedata.json', 'utf8')

I'm not sure how you run your code, so my example may not work in your codebase, but hopefully understanding where you went wrong will help debug your code.

相关文章

  • fs 读不到路径下文件 express

    https://stackoverflow.com/questions/48469666/error-enoent...

  • 2.根据路径的不同发送请求

    fs:file System读取文件:fs.readFile(文件路径,function(err,err){})读...

  • Node上传文件

    var fs = require('fs'); var express = require('express');...

  • fs.appendFile及appendFileSync

    fs.appendFile 语法:fs.appendFile("文件路径",data,function(err){...

  • node文件操作

    缓存区、文件系统、路径 1. 课程介绍 Ø Buffer缓存区(了解) Ø fs文件模块(了解) Ø fs读取文件...

  • HDFS Shell

    单个hdfs Shell文件操作 hadoop fs -cp 文件名 路径 将文件复制到路径...

  • nodejs fs 内置模块

    1. readFile 读取文件数据 语法异步读取:fs.readFile(目标文件绝对路径 , 回调函数)同步读...

  • node常用模块

    一、fs模块 1、判断路径文件是否存在 2、读取文件 3、写入文件注意:a、fs.writeFile方法只能用于创...

  • Node.js fs模块-rename()方法

    一. rename()方法-->文件重命名 1. 用法 fs.rename('旧文件路径','新文件路径',回调函...

  • (二) node.js 常用基础API

    一、path 路径 用于处理文件路径和目录路径的模块 二、fs 文件系统 用于与文件系统进行交互的模块 写入文件操...

网友评论

    本文标题:fs 读不到路径下文件 express

    本文链接:https://www.haomeiwen.com/subject/spfskftx.html