i created nodejs application port 7777.
server.js
'use strict'; var express = require('express'), router = require('./router'); var app = express(); var port = 7777; app.use(router()); app.listen(port); console.log('doctor appointment @ ' + port); i calling router server , executng application node server.js
router.js
'use strict'; var express = require('express'); var doctorappointment = require('./controllers/doctorappointment'); module.exports = function() { var options = { casesensitive: true }; console.log("router"); // instantiate isolated express router instance var router = express.router(options); router.post('/appointment', doctorappointment.takeappoiment); return router; } i calling controller method router. controller follows:
doctorappointment.js
'use strict'; exports.takeappoiment = function(req, res, next) { console.log("inside appointment"); } after execution, controller method not calling
system@dt-lnx-315:~/desktop/nodejs/doctor-appointment$ node server.js
router
doctor appointment @ 7777
and end point defined in http://localhost:7777/
coming cannot / in browser
and http://localhost:7777/appointment
showing cannot /appointment. how execute controller method?
you handling post requests /appointment line of code:
router.post('/appointment', doctorappointment.takeappointment);
change post get if need access page, so:
router.get('/appointment', doctorappointment.takeappointment);
also don't have handler index page, that's why getting error / path. can add handler similar way:
router.get('/', indexhandler);
Comments
Post a Comment