Skip to content

Instantly share code, notes, and snippets.

@vmetnev
Last active April 8, 2024 16:48
Show Gist options
  • Save vmetnev/d7efd5444e51fff5d6590c1ca9343526 to your computer and use it in GitHub Desktop.
Save vmetnev/d7efd5444e51fff5d6590c1ca9343526 to your computer and use it in GitHub Desktop.
POST request
getData()
async function getData() {
let url = "http://localhost:3001/test"
let resp = await fetch(url, {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
name: "Vlad455",
age: 25
})
})
resp = await resp.text()
console.log(resp)
}
// Server Side
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post("/test", (req, res) => {
res.send(req.body);
console.log(req.body);
});
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
app.listen(3001, () => {
console.log("server startered at post 3001");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment