Skip to content

Instantly share code, notes, and snippets.

View robertcoopercode's full-sized avatar

Robert Cooper robertcoopercode

View GitHub Profile
{
"name": "your-project-folder",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
const express = require('express');
const https = require('https');
const app = express();
app.listen(8080, () => {
console.log("The application is running on localhost:8080!");
});
app.get('/', (request, response) => {
response.sendFile(__dirname + '/index.html');
});
function getMediumData(callback) {
let mediumData = {};
https.get( {
host: 'medium.com',
path: '/@jaltucher/latest',
headers: {
Accept: 'application/json'
}
}, (response) => {
let rawData = '';
app.get('/mediumPosts', (request, response) => {
getMediumData( (mediumData) => {
response.send(mediumData);
});
});
<html>
<head>
<meta charset="UTF-8">
<title>Medium Blog Posts with Node.js</title>
</head>
<body>
</body>
</html>
<div id='page-wrapper'>
<div id="intro-section">
<h1>Medium Blog Posts</h1>
<p>Here is a list of the most recent blog posts from <a href="https://medium.com/@jaltucher" target="_blank">James Altucher</a>.</p>
</div>
<!-- Blog posts get appended here -->
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script>
$(document).ready( () => {
$.get( '/mediumPosts', (result) => {
for (let i=1; i <= 3; i++) {
let postId = '#post' + i;
let title = 'mediumTitle' + i;
let excerpt = 'mediumExcerpt' + i;
let url = 'mediumUrl' + i;
let postDiv = document.createElement('div');
postDiv.className = 'post';