fs.readFileSync不是功能Meteor,React [英] fs.readFileSync is not a function Meteor, React

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

问题描述

在尝试调用readFileSync()之后,我在Chrome调试器中得到了"fs.readFileSync不是函数"信息;

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.1 npm版本: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开发时.只想更新并说用户看到的内容与服务器看到的内容之间存在严重的根本差异.允许前端(流星,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天全站免登陆