“Bodyparser ausdrücken” Code-Antworten

Body-Parser NPM

$ npm install body-parser
Thankful Tortoise

Körperparser

var express = require('express')
  var bodyParser = require('body-parser')
  var app = express()
  // parseapplication/x-www-form-urlencoded
  app.use(bodyParser.urlencoded({ extended: false }))
  // parse application/json
  app.use(bodyParser.json()) app.use(function (req, res) {  res.setHeader('Content-Type', 'text/plain')  res.write('you posted:\n')  res.end(JSON.stringify(req.body, null, 2))})
Jules

Körperparser

<script>
const bodyParser = require("body-parser");

app.use(bodyParser.urlencoded({extended:true}));
  
app.post("/", function(req, res){
  let firstName = req.body.fNAME;
  
});
</script>

<input type="text" name="fNAME" placeholder="First Name">
Baba Falcon

Body Parser Express

app.use(express.json()); //Used to parse JSON bodies
Cute Cicada

Bodyparser ausdrücken

const express = require('express')
const bodyParser = require('body-parser')

const app = express()

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json
app.use(bodyParser.json())

app.use(function (req, res) {
  res.setHeader('Content-Type', 'text/plain')
  res.write('you posted:\n')
  res.end(JSON.stringify(req.body, null, 2))
})

Busy Butterfly

Bodyparser ausdrücken

/** @format */

const express = require("express");
const app = express();
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const PORT = process.env.PORT || 3000;

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));

// parse application/json
app.use(bodyParser.json());

//connecting to db
try {
    mongoose.connect('mongodb://localhost/YOUR_DB_NAME', {
        useNewUrlParser: true,
        useUnifiedTopology: true,
      	useCreateIndex: true,
      }, () =>
      console.log("connected"));
  } catch (error) {
    console.log("could not connect");
  }

app.get("/", (req, res) => {
  res.send("home");
});

app.listen(PORT, () => console.log(`Server is listening on port ${PORT}`));
Busy Butterfly

Ähnliche Antworten wie “Bodyparser ausdrücken”

Fragen ähnlich wie “Bodyparser ausdrücken”

Weitere verwandte Antworten zu “Bodyparser ausdrücken” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen