node.js - Express req.body undefined, routes after bodyParser doesn't work -


I do not know there are so many flaws and problems for basic tasks in programming. This is my code, it does not matter that I refuse to work on how many unique positional changes I make.

  var express = require ('express'); Var path = requirement ('path'); Var favicon = is required ('static-favicon'); Var Loger = Required ('Morgan'); Var requires cookieParser = ('cookie-parser'); Var bodyParser = is required ('body-parser'); Var app = express (); Var store = is required ('./pac / store'); App.use (favicon ()); App.use (logger ('god')); App.use (bodyParser.json ()); App.use (bodyParser.urlencoded ()); App.use (cookieParser ()); App.use (Required ('stylus'). Middleware (path.joined (__deirnam, 'public')); App Use (express.static (path.join (__derename, 'public')); // View engine setup app.set ('views', path.join (__dirname, 'views')); App.set ('visual engine', 'z'); App.get ('/', function (rik, ridge) {res.render ('home', {title: 'ninja store'})}); App.post ('/', function (rik, ridge) {username = req.body.username} 'Anonymous'; req.session.username = Username; res.redirect ('/');});   

It keeps saying

  Any help is appreciated Thanks, thanks     

I think that here req.session is undefined, no req. Body . Because this is property setting error.

If this req.body is undefined, then it will throw an error of read property

 < Code> Undefined property can not read 'username'   

You must use the middleware to address this problem. I hope this help.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -