fs.readFileSync 不是函数 Meteor, React [英] fs.readFileSync is not a function Meteor, React

查看:40
本文介绍了fs.readFileSync 不是函数 Meteor, React的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试调用 readFileSync() 后,我在 Chrome 调试器中收到fs.readFileSync is not a function";

I'm getting a 'fs.readFileSync is not a function' in Chrome debugger after trying to call readFileSync();

我称之为...

const fs = require('fs');

调用函数...

let content = fs.readFileSync('/path/to/my/file.stuff');

并尝试显示内容..

console.log(content);

我一无所获.当我这样做时...

I get nothing. When I do...

console.log(fs);

我似乎得到了一个通用的 javascript 对象...我完全被困住了.

I appear to get a generic javascript object... I'm completely stuck.

流星版本:1.5.1npm 版本:3.10.10节点版本:v6.10.1

Meteor version: 1.5.1 npm version: 3.10.10 node version: v6.10.1

推荐答案

感谢大家的回答!

我已经确认您不能在客户端使用 fs.

I have confirmed that you cannot use fs on the client side.

相反,我创建了另一个本地简单的 express 节点 api,而 react web 应用程序只是向节点 api 发出请求以获取该数据.

Instead, I made another local simple express node api and the react web app just makes a request back to the node api to get that data.

另外,你必须这样做......

Also, you have to do this...

https://enable-cors.org/server_expressjs.html

很久以前写的.3 年前,我刚刚开始学习 Web 开发.只是想更新一下,说用户看到的和服务器看到的有严重的根本区别.允许前端(Meteor、React、Angular 等)读取文件将是一个非常严重的安全问题.任何人都可以制作一个网站,当用户访问它时,它只会读取您本地计算机的文件.不好...

Wrote this a long time ago. 3 years back when I was just starting my web development learning. Just want to update and say that there is a serious fundamental difference between what the user sees and what the server sees. Allowing the front-end (Meteor, React, Angular, etc.) to read files would be a super serious security issue. Anyone could make a website that when a user goes to it, it would just read your local computers files. Not good...

虽然这对我来说现在非常明显,但在 3 年前并不明显.所以对于你们所有的新手来说,没关系:) 毫无疑问,这是一个愚蠢的问题.

While this is super obvious to me now, it wasn't obvious 3 years ago. So for all you newbies out there, it's okay :) No question is a dumb question.

这篇关于fs.readFileSync 不是函数 Meteor, React的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆