Created
July 26, 2020 01:31
-
-
Save internetsadboy/b082985031411e970fca7fe0f3b1d9cb to your computer and use it in GitHub Desktop.
"index.js" for express (upwork proposal question) - JARED LAMONT
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 path = require('path'); | |
// initialize app | |
const app = express(); | |
const port = 3000; | |
// assuming ~/public/index.html | |
app.get('/html', (req, res) => { | |
res.sendFile(path.join(__dirname, 'public', 'index.html')); | |
}) | |
// json example | |
app.get('/json', (req, res) => res.json({ please: 'hire me' })); | |
// geojson example | |
// GeoJSON uses the JSON standard | |
app.get('/geojson', (req, res) => { | |
res.json({ | |
"type": "Feature", | |
"geometry": { | |
"type": "Point", | |
"coordinates": [125.6, 10.1] | |
}, | |
"properties": { | |
"name": "Dinagat Islands" | |
}}) | |
} | |
); | |
app.listen(port, () => console.log(`express api test app => http://localhost:${port}`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment