相关疑难解决方法(0)

在Node.js中声明多个module.exports

我想要实现的是创建一个包含多个函数的模块.

module.js:

module.exports = function(firstParam) { console.log("You did it"); },
module.exports = function(secondParam) { console.log("Yes you did it"); }, 
// This may contain more functions
Run Code Online (Sandbox Code Playgroud)

main.js:

var foo = require('module.js')(firstParam);
var bar = require('module.js')(secondParam);
Run Code Online (Sandbox Code Playgroud)

firstParam遇到的问题是,它是一个对象类型,secondParam是一个URL字符串,但是当我有它时,它总是抱怨类型错误.

在这种情况下,如何声明多个module.exports?

module node.js

204
推荐指数
12
解决办法
22万
查看次数

标签 统计

module ×1

node.js ×1