Reference error on node.js while include file

后端 未结 2 1348
离开以前
离开以前 2021-01-19 19:13

I\'m new to node.js. i have two files. they are index.js and db.js

my index.js is

var connection =          


        
2条回答
  •  醉话见心
    2021-01-19 19:58

    if you want something from the db module to be accessible in other modules, you need to expose it, by using module.exports

    add to the end of your db.js file:

    module.exports = {
      appModel : appModel,
      Device : Device
    };
    

    and then in your index.js you can do:

    device = new connection.Device({
      id: 93,
      name: 'test1'
    });
    

    you can read more about it here

提交回复
热议问题