Node: import object array from another js file?

前端 未结 5 1033
伪装坚强ぢ
伪装坚强ぢ 2021-02-02 14:13

In a file called data.js, I have a big object array:

var arr = [ {prop1: value, prop2: value},...]

I\'d like to use this array into my Node.js

5条回答
  •  梦毁少年i
    2021-02-02 15:07

    You can directly get JSON or JSON array from any file in NODEJS there is no need to export it from a JS script

        [ {
            prop1: value, 
            prop2: value
          },
          {
            prop1: val,
            prop2: val2
          },
          ...
       ]
    

    Store it to a JSON file suppose test.json

    Now you can export it as given below its very simple.

    let data = require('./test.json');
    

提交回复
热议问题