Reputation: 3700
I am developing an app in node js using typescript and use the gulp transpiler in commonjs mode.
I have wrote a homeController.ts as:
let homeController={
getIndex:(req,res)=>{
res.send('Hello world'); //Compiles the file named "index" in the views directory (`/views`) using the view engine (Jade).
},
}
export default homeController;
and i have a separate route file for routing as route.ts
import home =require('../controller/homeController');
import express = require('express');
let router = express.Router();
router.get('/',home.getIndex);
module.exports = router;
and import it in server file as
import routes = require('./routes/route');
and route it as
app.use('/api', routes);
but when gulp compile these file it give the error
please correct me if i'm doing any mistake.
Upvotes: 3
Views: 4950
Reputation: 220964
Your homeController.ts file exports an object with the shape { default: { getIndex: ... } }
. It does not have a top-level getIndex
property.
You probably want to use export = homeController
instead of export default homeController
. They are not equivalent.
Upvotes: 4