“Express Return Json” Kod odpowiedzi

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

JSON JSON POST Express

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

węzeł JS powrót 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

Odpowiedzi podobne do “Express Return Json”

Pytania podobne do “Express Return Json”

Więcej pokrewnych odpowiedzi na “Express Return Json” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu