如何从流星应用程序内部读取本地文件系统中的文件? [英] How do I read a file from the local file system from inside a meteor app?

查看:45
本文介绍了如何从流星应用程序内部读取本地文件系统中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个流星应用程序,它需要定期读取位于应用程序包之外的主机文件系统上的文件.我正在使用 node 的 fs 来完成此操作,并且在我的 (macOS) 开发机器上运行良好.

I have a meteor app that needs to periodically read a file located on the host's file system, outside of the app package. I am using node's fs to accomplish this, and it works fine on my (macOS) development machine.

但是,当我运行 mup deploy 将其部署到我的(Ubuntu 14)服务器时,mup 在启动 Meteer 后返回以下错误:

However, when I run mup deploy to deploy it to my (Ubuntu 14) server, mup returns the following error after starting meteor:

错误:ENOENT:没有那个文件或目录,打开'/home/sam/data/all_data.json'在 Object.fs.openSync (fs.js:652:18)在 Object.fs.readFileSync (fs.js:553:33)

有人知道为什么会发生这种情况吗?

Does anyone know why this might be happening?

推荐答案

您应该密切关注 mup 文档.您是否在 mup 配置中看到过卷设置?试试这个来解决你的问题.

you should follow mup documentation closely. Have you seen volumes setup in mup config? Try this to solve your issue.

原因:mup 在 docker 中运行应用程序,除非指定,否则无法访问主机文件系统.卷设置通过 mup 部署为您执行此操作.

Reason: mup runs app in docker without any access to host file system unless specified. Volumes setup does this for you with mup deployment.

下面是来自 http://meteor-up.com/docs.html 的 mup 配置的一部分,一切都已配置,阅读更多内容以获得更好的想法.

Below is the part of mup config from http://meteor-up.com/docs.html, Everything Configured, read more to get a better idea.

    name: 'app',
    path: '../app',

    // lets you add docker volumes (optional). Can be used to
    // store files between app deploys and restarts.
    volumes: {
      // passed as '-v /host/path:/container/path' to the docker run command
      '/host/path': '/container/path',
      '/second/host/path': '/second/container/path'
    },

这篇关于如何从流星应用程序内部读取本地文件系统中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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