Wednesday 21 August 2019

[Help] Express can't get POST data

I have used express before to do this, getting data posted to a URL, but it does not seem to be working. I keep getting undefined. Using postman I am able to get to the function just fine and do anything I need to except get that data. What am I doing wrong? I can't seem to figure out the dumb mistake I am making.-- Server.js --const express = require('express');const app = express();//app.use(express.json());app.use(express.urlencoded());const todo = require('./routes/api/todo');app.use('/api/todo', todo);const port = process.env.PORT || 5000;app.listen(port, () => console.log(\Server started on port ${port}`));`​-- TODO.js --const express = require('express');const SQL = require('../../sql/sql.js');const router = express.Router();// Add todorouter.post('/', (req, res) => {console.log(req.body);res.send(req.body);});module.exports = router;

Submitted August 22, 2019 at 06:02AM by gemurdock

No comments:

Post a Comment