(Very) basic express setup
This commit is contained in:
parent
fb815863d6
commit
6755625764
@ -16,9 +16,12 @@
|
|||||||
"author": "Linus Miller <lohfu@lohfu.io> (https://lohfu.io/)",
|
"author": "Linus Miller <lohfu@lohfu.io> (https://lohfu.io/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"body-parser": "^1.18.2",
|
||||||
|
"chalk": "^2.3.0",
|
||||||
"express": "^4.16.2",
|
"express": "^4.16.2",
|
||||||
"handlebar": "^1.0.0",
|
"handlebar": "^1.0.0",
|
||||||
"knex": "^0.14.2",
|
"knex": "^0.14.2",
|
||||||
|
"morgan": "^1.9.0",
|
||||||
"node-fetch": "^1.7.3"
|
"node-fetch": "^1.7.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@ -1,7 +1,28 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const fetch = require('node-fetch')
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
|
||||||
|
|
||||||
fetch('https://google.com')
|
const express = require('express')
|
||||||
.then((res) => res.text())
|
const bodyParser = require('body-parser')
|
||||||
.then((html) => console.log(html))
|
const chalk = require('chalk')
|
||||||
|
|
||||||
|
const server = express()
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
const morgan = require('morgan')
|
||||||
|
|
||||||
|
server.use(morgan('dev'))
|
||||||
|
}
|
||||||
|
|
||||||
|
server.use(bodyParser.json())
|
||||||
|
server.use(bodyParser.urlencoded({ extended: true }))
|
||||||
|
|
||||||
|
server.use('/', (req, res, next) => {
|
||||||
|
console.log('hello')
|
||||||
|
res.send('<h1>Hello</h1>')
|
||||||
|
})
|
||||||
|
|
||||||
|
const port = process.env.port || 1337
|
||||||
|
|
||||||
|
server.listen(port, () => {
|
||||||
|
console.info(`[${chalk.cyan('INIT')}] HTTP Server listening on port ${chalk.magenta(port)} (${chalk.yellow(server.get('env'))})`)
|
||||||
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user