Skip to content

Instantly share code, notes, and snippets.

@koraytugay
Created August 1, 2021 22:00
Show Gist options
  • Select an option

  • Save koraytugay/a37416fb2ecfedc3d7cde7f4d4edce99 to your computer and use it in GitHub Desktop.

Select an option

Save koraytugay/a37416fb2ecfedc3d7cde7f4d4edce99 to your computer and use it in GitHub Desktop.
Express Server
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
.photoContainer {
margin: 10px
}
</style>
</head>
<body>
<div id="container" style="padding: 20px">
<div id="loading">Loading..</div>
</div>
<script>
window.onload = () => {
searchFlickr();
}
async function searchFlickr() {
let response = await fetch("http://127.0.0.1:9999/api/posts");
let data = await response.json();
console.log(data);
}
</script>
</body>
</html>
const express = require('express')
const POSTS = {
'1': {
'post': 'This is the first blog post.'
},
'2': {
'post': 'This is the second blog post.'
},
'3': {
'post': 'This is the second blog post.'
}
}
const SERVER_PORT = 9999;
const serverApp = express();
serverApp.use(express.static(__dirname));
serverApp.get('/api/posts', function(req, resp) {
resp.json(POSTS);
})
serverApp.listen(SERVER_PORT, function() {
console.log('Started server at http://127.0.0.1:' + SERVER_PORT);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment