My code is as shown below:
app.js
const app = express();
const itemsRouter = require('./routes/items.js');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use('/items', itemsRouter);
items.js
const router = require('express').router;
router.get('/itemTest', (req, res) => {
res.json({
sucess: true
});
console.log(`the parametrs are ${req.body.item_name} ${req.body.item_post}`);
});
module.exports = router;
But here somehow, I am not able to get the router working and it says that can not read property 'get' of undefined.
the error stack is as shown below:
TypeError: Cannot read property 'get' of undefined
at Object.<anonymous> (C:\Users\anand\quFlipApi\routes\items.js:5:7)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\anand\quFlipApi\app.js:33:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
via M thaker
No comments:
Post a Comment