Node: import object array from another js file?

前端 未结 5 1032
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 14:53

    I know how to export functions, [...]

    An array, or really any value, can be exported the same as functions, by modifying module.exports or exports:

    var arr = [ {prop1: value, prop2: value},...];
    
    exports.arr = arr;
    
    var arr = require('./data').arr;
    

提交回复
热议问题