Created
April 26, 2018 20:34
-
-
Save stevenleelawson/96f642361387fa857f820d03a1228c08 to your computer and use it in GitHub Desktop.
express tutorial
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
const express = require('express'); | |
const app = express(); | |
const data = require('./data.json'); | |
const urlLogger = (request, response, next) => { | |
console.log('REquest URL:', request.url); | |
next(); | |
} | |
const timeLogger = (request, response, next) => { | |
console.log('DAteTime:', new Date(Date.now()).toString()); | |
next(); | |
} | |
app.use(urlLogger, timeLogger); | |
app.use(express.static('public')); | |
app.use((req, res, next) => res.status(404).send('cand find that')); | |
app.get('/json', (request, response) => { | |
response.status(200).json(data); | |
}); | |
app.get('/', (request, response) => { | |
}); | |
app.get('/sunsets', (request, response) => { | |
}); | |
app.use(express.static('public/sunsets')); | |
app.listen(3000, () => { | |
console.log('express be runnin on localhost:3000') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment