Skip to content

Instantly share code, notes, and snippets.

View robertcoopercode's full-sized avatar

Robert Cooper robertcoopercode

View GitHub Profile
// Require the necessary modules
const loremIpsum = require("./generator.js");
const querystring = require("querystring");
const fs = require("fs");
// Require express and create an express router object
const express = require('express');
const router = express.Router();
// Route that serves index.html
// Require the necessary modules
const loremIpsum = require("./generator.js");
const querystring = require("querystring");
const fs = require("fs");
// Require express and create an express router object
const express = require('express');
const router = express.Router();
// Route that serves index.html
router.get('/', (request, response) => {
response.setHeader('Content-Type', 'text/html');
// Capture the contents of index.html in a variable
let fileContents = fs.readFileSync("./public/index.html", {encoding: "utf8"});
// Send a response to the client with the index.html file
response.write(fileContents);
response.end();
});
// Route that generates the lorem ipsum text and reloads a modified index.html
router.post('/', (request, response) => {
request.on("data", function(inputValue) {
// Convert the POST data into a readable string
let query = inputValue.toString(); // i.e. numberOfParagraphs=3
// Parse the query into a key/value pair and store the value of numberOfParagraphs
// in a variable
let numberOfParagraphs = querystring.parse(query).numberOfParagraphs;
// Generate the lorem ipsum text with the getAllParagraphs function
let loremIpsumText = loremIpsum.getAllParagraphs(numberOfParagraphs);
// Code that generates the random lorem ipsum text
// Create a new object called loremIpsum by invoking the GenerateNewText constructor function
const loremIpsum = new GenerateNewText();
// Constructor function that creates an object with the sentences property
function GenerateNewText() {
// Add property to the object
this.sentences =
[
// Constructor function that creates an object with the sentences property
function GenerateNewText() {
// Add property to the object
this.sentences =
[
"Awesome quote number 1.",
"Second awesome quote.",
"Yet another great quote.",
"Ok, last quote."
];
...
collections:
- name: "meetups"
label: "Meetups"
description: "Meetup dates, location, and presenter information."
folder: "src/pages/meetups"
create: true
fields:
- { label: "Template Key", name: "templateKey", widget: "hidden", default: "meetup" }
...
export const aboutPageQuery = graphql`
query AboutPage($id: String!) {
markdownRemark(id: { eq: $id }) {
html
frontmatter {
title
mainImage {
image
...
const AboutPage = ({ data }) => {
const { markdownRemark: page, footerData, navbarData } = data;
const {
frontmatter: {
seo: { title: seoTitle, description: seoDescription, browserTitle },
},
} = page;
# NPM Installation Method
npm install --global typescript # Global installation
npm install --save-dev typescript # Local installation
# Yarn Installation Method
yarn global add typescript # Global installation
yarn add --dev typescript # Local installation