“Express Return JSON” Code-Antworten

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 Anfrage 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

Knoten JS gibt JSON zurück

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

Ähnliche Antworten wie “Express Return JSON”

Fragen ähnlich wie “Express Return JSON”

Weitere verwandte Antworten zu “Express Return JSON” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen