【发布时间】:2018-02-27 15:11:51
【问题描述】:
我正在尝试在我的 express js 应用程序中学习本地模块设置。
test-module 文件夹在我的项目文件夹中创建,它包含两个文件
1)index.js
module.exports = {
indexfunc:function(){
console.log('ok from index');
}
}
2)hello.js.
module.exports = {
helloFunc:function(){
console.log('ok from hello');
}
}
在app.js 文件中导入这个模块
var mymodule = require('hello-module');
console.log(mymodule);
output:{ indexfunc: [Function: indexfunc] }
但这会返回console.log(require('hello-module').hello) undefined。
这个模块的package.json
{
"name": "hello-module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
【问题讨论】:
标签: javascript node.js express module