Express.js - export/access function within route file

ساخت وبلاگ

Vote count: 0

I am trying to export function within route file. Here is my code in user.js

var express = require('express');
var router = express.Router();
router.post("/test", function (req, res, next) { res.send("success");
});
var funDef=function(){
console.log("export a function")
}
moudle.exports=router;

How can I export or call funDef in another js file. I tried the following way but it is not working

var readFun= require("./user.js");
readFun.funDef();

Can anyone guide me?

asked 30 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 301 تاريخ : دوشنبه 31 خرداد 1395 ساعت: 18:11