美文网首页
nodejs 导出和引入文件的操作

nodejs 导出和引入文件的操作

作者: 云龙789 | 来源:发表于2019-02-21 18:15 被阅读0次

比如我需要将 Gift.js 文件的内容,被 index.js 引入

  • Gift.js
function Gift() {
}

Gift.prototype = {
    init(socket,io) {
        console.log('init run');
        console.log(`socket`, socket);
node
        socket.on('chat room message', msg => {  // 发送给某个房间
            console.log(msg);
            io.emit('chat room receive' + msg.roomNum, msg)
        });
        socket.on('sendgift', msg => {
            // 发送给某个房间
            io.emit('recvgift' + msg.roomNum, msg)
        });

    }
}

module.exports = Gift;
  • Index.js
const Gift = require('./mobile/Gift');
...
  let gift = new Gift();
  gift.init(socket,io);
...

相关文章

网友评论

      本文标题:nodejs 导出和引入文件的操作

      本文链接:https://www.haomeiwen.com/subject/rzydyqtx.html