简体   繁体   中英

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).

In another sub-directory of server there is a y.json file; I want to use its content in x.js .

It must be very easy, but nothing yet has helped me,

thanks!

Just include it in your js file

var myJson = require('path_to_your_json');
// json file contains {"myValue": "resolved"}

console.log(myJson.myValue); // Prints "resolved";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM