“Ekspres Bodyparser” Kode Jawaban

NPM Body-Parser

$ npm install body-parser
Thankful Tortoise

Parser tubuh

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

Parser tubuh

<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

Ekspres 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

Ekspres 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

Jawaban yang mirip dengan “Ekspres Bodyparser”

Pertanyaan yang mirip dengan “Ekspres Bodyparser”

Lebih banyak jawaban terkait untuk “Ekspres Bodyparser” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya