“Express return json” Ответ

Parse Json Express

// Update for Express 4.16+
// Starting with release 4.16.0, a new express.json() middleware is available.
var express = require('express');
var app = express();

app.use(express.json());

app.post('/', function(request, response){
  console.log(request.body);      // your JSON
   response.send(request.body);    // echo the result back
});

app.listen(3000);
Mushy Magpie

Node Express Post запрос 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);
just-saved-you-a-stackoverflow-visit

Express return json

res.status(200).json({ message: "Hello world" })
Code Cat

Узел 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}
Jules

Express REQ GET JSON

const express = require('express');
const app = express();

app.use(express.json());

app.post('*', (req, res) => {
  req.body;	// The json object sent to the server
});
const port = 3000;
app.listen(port, () => console.log(`Listening on port ${port}.`));
garzj

Express return json

const express = require("express")
const port = process.env.PORT || 5000;

const app = express();

app.listen(port, () => console.log("Server startet at port ", port));

app.get("/api/goals", (req, res) => {
    res.status(200).json({ message: "Get goals" })
})
ofroog

Ответы похожие на “Express return json”

Вопросы похожие на “Express return json”

Больше похожих ответов на “Express return json” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования