There is the following form:
<form id="form" action="/" method="post"> <input type="text" id="title"> <input type="text" id="data"> <input type="submit" id="submit" value="ΠΎΡΠΏΡΠ°Π²ΠΈΡΡ"> </form> and server.js file:
var express = require("express"); var bodyParser = require('body-parser'); var multer = require('multer'); // v1.0.5 var upload = multer(); // for parsing multipart/form-data var app = express(); app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.set("view engine","ejs"); app.use(express.static(__dirname + "/public")); app.get("/", function(req,res){ res.render("pages/index", { title: "ΠΠ»Π°Π²Π½Π°Ρ", msg: "ΠΡΠΈΠ²Π΅Ρ ΠΠΈΡ!", data: q, info: "" }); }); app.post('/', upload.array(), function (req, res, next) { console.log(req.body); //{} console.log(req.body.title); //undefined console.log(req.body.data); //undefined res.json(req.body); //{} }); app.get("/hello", function(req,res){ res.render("pages/other", { title: "ΠΡΡΠ³Π°Ρ ΡΡΡΠ°Π½ΠΈΡΠ°", msg: "hello world" }); }); app.use(function(req, res, next) { res.status(404).render("pages/error", { title: "ΠΎΡΠΈΠ±ΠΊΠ° 404", msg: "ΠΎΡΠΈΠ±ΠΊΠ° 404" }); res.status(500).render("pages/error", { title: "ΠΎΡΠΈΠ±ΠΊΠ° 500", msg: "ΠΎΡΠΈΠ±ΠΊΠ° 500" }); }); app.listen(8080); console.log("Π‘Π΅ΡΠ²Π΅Ρ Π·Π°ΠΏΡΡΠ΅Π½!"); I do it by tutorials, I recently started to deal with this, I came across the fact that I created the form, but I cannot receive data on the server in any way. tried both req.query and req.params ('title') - undefined.
Packages installed that connect.
Actually ... a lot of information in English - maybe I'm missing something?
Question: How to get data from the form transmitted by the post method and process it on the server using nodejs and express.js technologies?