Answers for "send json express"

3

node express post request json

var express = require('express');

var app = express();

app.use(express.json()); // built-in middleware for express

app.post('/', function(request, response){
 	let myJson = request.body;      // your JSON
	let myValue = request.body.myKey;	// a value from your JSON
	response.send(myJson);	 // echo the result back
});

app.listen(3000);
Posted by: Guest on March-29-2020
-1

node js return json

var http = require('http');

var app = http.createServer(function(req,res){
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify({ a: 1 }));
});
app.listen(3000);

// > {"a":1}
Posted by: Guest on June-19-2020
0

express json body

var bodyParser = require('body-parser')
Posted by: Guest on March-04-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language