我試圖從一個Node.js的腳本傳遞函數回答另一個通參數功能從一個JS Node.js加載到另一個
這裏是我想。 Index.js
var express = require('express');
require('./meter');
var app = express();
app.get('/',function(req,res){
return; //hi function from another file
})
app.listen(3000);
console.log('listening on 3000 port')
meter.js
module.exports = {
hi: function(req, res) {
return res.status(200).json({"message" : "Hello V1"});
}
};
確實需要的功能只是將做的工作?
在此先感謝。
是的。但是你必須在'meter.js'中輸出'hi',你必須使用它,類似於你爲了表達而做的。 –
謝謝@PratikGaikwad。但我明白你在說什麼,但不知道該怎麼做。請你可以在答案 –
中寫一點代碼,請看下面Nir Levy發佈的答案。 –