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}`))
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}`))
create express app
## Command
$ npx express-generator
: 'For earlier Node versions, install the application generator as a global
npm package and then launch it':
$ npm install -g express-generator
$ express
## Display the command options with the -h option:
$ express -h
require express server.js
const express = require('express')const app = express() app.get('/', function (req, res) { res.send('Hello World')}) app.listen(3000)
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}`)
})
express nodejs
Fast, unopinionated, minimalist web framework for Node.js
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us