Answers for "node.js express example"

49

express js basic example

//to run : node filename.js
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}`))

//visit localhost:3000
// assuming you have done 1) npm init 2) npm install express
Posted by: Guest on July-17-2020
4

sample express app

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 May-12-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

Code answers related to "Javascript"

Browse Popular Code Answers by Language