Skip to content

Instantly share code, notes, and snippets.

@stevenleelawson
Created April 26, 2018 20:34
Show Gist options
  • Save stevenleelawson/96f642361387fa857f820d03a1228c08 to your computer and use it in GitHub Desktop.
Save stevenleelawson/96f642361387fa857f820d03a1228c08 to your computer and use it in GitHub Desktop.
express tutorial
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