Answers for "expressJS doc"

5

nodejs express api

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

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

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

express

const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
require('dotenv').config()
const ObjectId = require("mongodb").ObjectId;

const app = express()
app.use(cors())
app.use(express.json())
const port = process.env.PORT || 5000;

app.get('/', (req, res)=>{
    res.send('welcome to backend')
})

app.listen(port, () => {
    console.log(`App listening at localhost:${port}`);
})
Posted by: Guest on June-19-2021
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