Created
March 6, 2021 09:27
-
-
Save shershen08/f0827a44a1de62e80a6278a33c5802d4 to your computer and use it in GitHub Desktop.
expressjs demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
//import express from 'express' | |
app = express(); | |
const port = process.env.PORT || 9999; | |
console.log(process.env.PORT) | |
//app.set('port', 8080); | |
// | |
app.use(express.static(__dirname)); | |
app.set('view engine', 'pug') | |
app.get('/', (req, res) => { | |
// validation | |
console.log(req.query.search) | |
// res.status(400).send('Invalid data') | |
// DB | |
//res.status(500).send('DB error') | |
// create response | |
// res.send('Hello World!') | |
//200, app/json | |
res.json({foo: 'bar'}) | |
}) | |
app.get('/pages/post', (req, res) => { | |
res.render('index', { | |
title: 'aaa', | |
message: 'aaa', | |
post:' create response' | |
}) | |
}) | |
app.post('/send-data', (req, res) => { | |
res.send('Hello World!') | |
}) | |
app.listen(process.env.PORT, function() { | |
console.log('Server started: http://localhost:' + process.env.PORT + '/'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment