Open DeanPaul opened 6 years ago
postman header
body
curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: cbc7893b-f2b6-1aeb-b39f-4c32c948baf5" -d '{"a":2}' "http://localhost:3000/api/test"
var data = JSON.stringify({
"a": 2
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "http://localhost:3000/api/test");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.setRequestHeader("postman-token", "c3d5657c-a802-c9cc-6129-c56d0ef74b74");
xhr.send(data);
Create a Node project
npm init
Set up an Express Node server
Install Express
npm install express --save-dev
Start server
package.json
create index.js
npm run start
Add Router
npm install --save body-parser