H
H
HAbRAhabp2015-12-20 18:00:43
Node.js
HAbRAhabp, 2015-12-20 18:00:43

Why doesn't bodyparser work?

I'm learning node.js
Help me figure out why POST request parsing doesn't work
app.use(express.bodyParser());
The code itself:

// модули
var express = require('express'),
    jade = require ('jade'),
    app = express();

// генерация рандомного числа
function rand(min, max) {
    var i = (Math.random() * 32768) >>> 0;
    return (i % (min - max)) + min;
}

app.use(express.bodyParser());

app.set('view engine', 'jade');

app.get('/', function (req, res) {
    res.render('index', { title: 'title', message: rand(1, 10000)});
})

app.post('/', function (req, res) {
    console.log (req.body.user);
    debugger;
    res.render('index', { title: 'title', message: req.body.user.name});
})

app.get('/user/:id/red', function (req, res) {
    res.send('Hello user ' + req.params.id)
})

var server = app.listen(3000)

Exception takes off
"D:\work\WebStorm 11.0.2\bin\runnerw.exe" C:\nodejs\node.exe --debug-brk=59643 --nolazy server.js
Debugger listening on port 59643
d:\nodep\node_modules\express\lib\express.js:99
      throw new Error('Most middleware (like ' + name + ') is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.');
      ^

Error: Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
    at Function.__dirname.forEach.Object.defineProperty.get (d:\nodep\node_modules\express\lib\express.js:99:13)
    at Object.<anonymous> (d:\nodep\server.js:12:16)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.runMain [as _onTimeout] (module.js:430:10)
    at Timer.listOnTimeout (timers.js:92:15)

Process finished with exit code 1

index.jade
html
    head
        title!= title
    body
        h1#master.test!= message
        hr
        form(method="POST", action="/")
            input(type="text", name="user[name]", placeholder="name")
            input(type="password", name="user[pass]", placeholder="pass")
            input(type="submit")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
un1t, 2015-12-20
@HAbRAhabp

Well, it says
Most middleware is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question