node.js - Router.use() requires middleware function but got a Object at Function.use -
code contact.js :
var express = require('express'); var router = express.router(); var nodemailer= require('nodemailer'); var dateformat = require('dateformat'); var = new date(); // basic usage dateformat(now, "dddd, mmmm ds, yyyy, h:mm:ss tt"); /* home page. */ router.get('/', function(req, res, next) { res.render('contact', { title: 'contact' }); }); router.post('/send', function(req, res, next) { verifyrecaptcha(req.body["g-recaptcha-response"], function(success) { if (success) { res.end("success!"); // todo: registration using params in req.body var transporter = nodemailer.createtransport({ service: 'gmail', auth: { user : 'email@gmail.com', pass : 'pass' } }); var mailoptions = { from: 'thiyagaraj <email@gmail.com>', : 'email@gmail.com', subject : +req.body.from , text : 'order placed ' }; transporter.sendmail(mailoptions, function(error, info){ if(error){ console.log(error); res.redirect('/'); }else{ console.log('message sent'); res.redirect('/'); } }); } else { res.end("captcha failed, sorry."); // todo: take them previous page res.render('about', { title: 'about' }); } }); }); /* }); module.exports = router; */
this recaptcha verification ... there special dependency required ? or there mistake code ................................... ...................................
thanks in advance :)
last line of router needs uncommented.
module.exports = router;
this code exposes router app. i'm guessing have requiring file somewhere , passing in app.use
, file isn't exporting (because it's commented out) app.use
expecting function getting undefined.
Comments
Post a Comment