[英]How to get JSON file in node.js?
In my app I have directory server
and sub-directory x
and within this directory there is a file called x.js
(written using node.js). 在我的应用程序中,我有目录
server
和子目录x
并且在此目录中有一个名为x.js
的文件(使用node.js编写)。
In another sub-directory of server
there is a y.json
file; 在
server
另一个子目录中,有一个y.json
文件; I want to use its content in x.js
. 我想在
x.js
使用其内容。
It must be very easy, but nothing yet has helped me, 一定很容易,但是还没有任何帮助,
thanks! 谢谢!
Just include it in your js file 只需将其包含在您的js文件中
var myJson = require('path_to_your_json');
// json file contains {"myValue": "resolved"}
console.log(myJson.myValue); // Prints "resolved";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.