“Expresse BodyParser” Respostas de código

NPM de pádega corporal

$ npm install body-parser
Thankful Tortoise

Analisador corporal

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

Analisador corporal

<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

Expresse BodyParser

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

Expresse BodyParser

/** @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

Respostas semelhantes a “Expresse BodyParser”

Perguntas semelhantes a “Expresse BodyParser”

Mais respostas relacionadas para “Expresse BodyParser” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código