Code files
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
'use strict'
|
||||
|
||||
const express = require('express')
|
||||
const {join} = require('path')
|
||||
const winston = require('winston')
|
||||
const expressWinston = require('express-winston')
|
||||
const index = require('./routes/index')
|
||||
const logger = new winston.Logger({
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
json: true
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
const app = express()
|
||||
const dev = process.env.NODE_ENV !== 'production'
|
||||
const port = process.env.PORT || 3000
|
||||
|
||||
app.set('views', join(__dirname, 'views'))
|
||||
app.set('view engine', 'ejs')
|
||||
|
||||
app.use(expressWinston.logger({
|
||||
winstonInstance: logger
|
||||
}))
|
||||
|
||||
if (dev) {
|
||||
app.use(express.static(join(__dirname, 'public')))
|
||||
}
|
||||
|
||||
app.use('/', index)
|
||||
|
||||
app.listen(port, () => {
|
||||
logger.info(`Server listening on port ${port}`)
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "app",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"ejs": "^2.5.6",
|
||||
"express": "^4.15.2",
|
||||
"express-winston": "^2.3.0",
|
||||
"winston": "^2.3.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
body {
|
||||
padding: 50px;
|
||||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
const {Router} = require('express')
|
||||
const router = Router()
|
||||
|
||||
router.get('/', function(req, res) {
|
||||
const title = 'Express'
|
||||
res.render('index', {title: 'Express'})
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title> <%= title %> </title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1> <%= title %> </h1>
|
||||
<p> Welcome to <%= title %> </p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user