Answers for "node express documentation"

5

express redirect

res.redirect('/foo/bar')
res.redirect('http://example.com')
res.redirect(301, 'http://example.com')
res.redirect('../login')
Posted by: Guest on December-13-2019
6

require express server.js

const express = require('express')const app = express() app.get('/', function (req, res) {  res.send('Hello World')}) app.listen(3000)
Posted by: Guest on March-19-2020
0

express in node js

$ npm init --y //add the package.json file

$ npm install express --no-save

const express = require('express')
const app = express()

//cors to fix cors origin, body-parser to fix the post value on the server
const cors = require('cors');
const bodyParser = require('body-parser');
app.use(cors());
app.use(bodyParser.json());

const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

router.get('/admin/:id?', (req, res) => {
  let id = req.params.id;
}

app.post('/admin', (req, res) => {
  const user = req.body.user;
  res.send('Hello World!', user)
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})
Posted by: Guest on August-28-2021
0

node express

npm install express --save
Posted by: Guest on July-11-2020
0

express render

// send the rendered view to the client
res.render('index')

// if a callback is specified, the rendered HTML string has to be sent explicitly
res.render('index', function (err, html) {
  res.send(html)
})

// pass a local variable to the view
res.render('user', { name: 'Tobi' }, function (err, html) {
  // ...
})
Posted by: Guest on December-13-2019

Code answers related to "Javascript"

Browse Popular Code Answers by Language