Skip to content

Instantly share code, notes, and snippets.

@veritymissed
Last active July 29, 2022 17:25
Show Gist options
  • Save veritymissed/eb9093e391f94d5d1ef3d467049ccba8 to your computer and use it in GitHub Desktop.
Save veritymissed/eb9093e391f94d5d1ef3d467049ccba8 to your computer and use it in GitHub Desktop.
在JS/Nodejs檔案內require/import JSON檔/物件

在js檔案內直接引入JSON檔

//As of node v0.5.x yes you can require your JSON just as you would require a js file.

var someObject = require('./somefile.json')
//這樣somObject就是object形式了

//In ES6:

import someObject from ('./somefile.json')
@Danny101201
Copy link

讚喔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment