This file contains hidden or 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 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); |
This file contains hidden or 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 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') |
This file contains hidden or 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
| <!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"> |
This file contains hidden or 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 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'}); |
This file contains hidden or 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 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'); |
This file contains hidden or 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 app = express() | |
| app.use(express.static('public')); | |
| app.set('view engine', 'ejs') | |
| app.get('/', function (req, res) { | |
| res.render('index'); | |
| }) | |
| app.listen(3000, function () { |
This file contains hidden or 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
| <!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"> |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| // 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 |
This file contains hidden or 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
| // 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' |