【问题标题】:sailsjs not picking local updated jsonsailsjs 没有选择本地更新的 json
【发布时间】:2016-07-15 08:29:35
【问题描述】:

在这个sailsjs 应用程序中,我们没有使用任何数据库。数据文件夹中的文件夹中有多个 json 文件(您可以在根级别看到它)。 我们正在访问的内部控制器像

req.session.categories = require(require('path').resolve('data/catInfo.json'));

catInfo.json 通过一些 cron 作业每天更新两次。问题是sailsjs 没有获取更新的数据,但是如果我重新启动服务器,那么它正在获取新数据。它在某处存储旧 json 并提供旧 json。

我已经检查过的内容:

1. try new browser / incognito browser. so this is not a session issue.
2. data folder is not under assets folder. so it is not going under .tmp folder.

那么旧数据存储在哪里?

【问题讨论】:

    标签: javascript json node.js sails.js


    【解决方案1】:

    require 包含的模块被缓存,这意味着 JSON 文件也是。

    如果文件正在更新,那么您需要使用fs 模块读取它。

    req.session.categories = 
        JSON.parse(
            require('fs').readFileSync(require('path').resolve('data/catInfo.json'))
        );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      相关资源
      最近更新 更多