Skip to content

Instantly share code, notes, and snippets.

View bmorelli25's full-sized avatar
๐Ÿ“š
Writing docs

Brandon Morelli bmorelli25

๐Ÿ“š
Writing docs
View GitHub Profile
@bmorelli25
bmorelli25 / index.js
Created June 20, 2017 12:41
node.js weather app
const request = require('request');
const argv = require('yargs').argv;
let apiKey = '*****************************';
let city = argv.c || 'portland';
let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&units=imperial&appid=${apiKey}`
request(url, function (err, response, body) {
if(err){
console.log('error:', error);
@bmorelli25
bmorelli25 / server.js
Created June 24, 2017 15:45
weather website with node
const express = require('express');
const bodyParser = require('body-parser');
const request = require('request');
const app = express()
const apiKey = '*****************';
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs')
@bmorelli25
bmorelli25 / index.ejs
Created June 24, 2017 15:45
weather website with node
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<link rel="stylesheet" type="text/css" href="/css/style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="container">
@bmorelli25
bmorelli25 / server.js
Created June 24, 2017 15:47
app.post()
const request = require('request');
const apiKey = '*****************';
//...
//...
app.post('/', function (req, res) {
let city = req.body.city;
let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&units=imperial&appid=${apiKey}`
request(url, function (err, response, body) {
if(err){
res.render('index', {weather: null, error: 'Error, please try again'});
@bmorelli25
bmorelli25 / server.js
Created June 24, 2017 15:48
weather website partial
const express = require('express');
const bodyParser = require('body-parser');
const app = express()
app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs')
app.get('/', function (req, res) {
res.render('index');
@bmorelli25
bmorelli25 / server.js
Created June 24, 2017 15:49
weather website partial
const express = require('express');
const app = express()
app.use(express.static('public'));
app.set('view engine', 'ejs')
app.get('/', function (req, res) {
res.render('index');
})
app.listen(3000, function () {
@bmorelli25
bmorelli25 / index.ejs
Created June 24, 2017 15:50
weather website partial ejs file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<link rel="stylesheet" type="text/css" href="/css/style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="container">
@bmorelli25
bmorelli25 / index.pug
Created June 26, 2017 21:12
Weather Website - Using Pug.js
doctype html
html
head
meta(charset='utf-8')
title Test
link(rel='stylesheet', type='text/css', href='/css/style.css')
link(href='https://fonts.googleapis.com/css?family=Open+Sans:300', rel='stylesheet', type='text/css')
body
.container
fieldset
@bmorelli25
bmorelli25 / speak.js
Last active July 6, 2017 14:09
local
// Example of accessing variables INSIDE the function
// words is a LOCAL variable
function speak(){
var words = 'hi';
console.log(words);
}
speak(); // 'hi'
console.log(words); // Uncaught ReferenceError: words is not defined
// Example of accessing variables OUTSIDE the function
// words is a GLOBAL variable
var words = 'hi';
function speak(){
console.log(words);
}
speak(); // 'hi'
console.log(words); // 'hi'