Coder Social home page Coder Social logo

node-cli-weather's Introduction

Node CLI Weather

Note: This will be a pair programming activity. After the previous lesson, how comfortable are you with completing the steps below? After a fist-to-five, find a similar number to pair up with. Choose one computer to work on, and a driver to start coding.

Today we will use Node.js to make a request to Weather Underground. Here are the steps to get set up. If you get stuck, remember to Read, Search, then Ask.

  1. Get an API key from Weather Underground.
  2. Set up your initial npm environment.
  3. Create index.js.
  4. Place your API key in a separate env.js file.

Getting an API key

If you already have an API key from the last execise, you can skip this step.

  1. Go to Weather Underground.
  2. Sign up for an account by clicking the "Join" link at the top right and following the steps.
  3. Wait a few seconds, then check your email for a Verification email of Weather Underground. You may need to check your spam or other folders.
  4. Click the "Validate Your Email" button.
  5. Return to Weather Underground
  6. Click the "More" dropdown and select "Weather API for Developers" near the bottom of the dropdown.
  7. Click the "Pricing" tab to "purchase" a free key and follow the steps. You may need to refresh the page if it claims you have not validated your email yet.
  8. Your API key will be displayed on the page.

Setting up a node environment

Do the following inside your WDI work folder.

  1. Fork and clone this repo.
  2. Enter the node-cli-weather directory.
  3. Run npm install to install all the dependencies.

index.js

  1. Require the request library so you can reach the weatherUnderground service.
  2. Look at the Weather Underground API Documentation to find a way to get JSON weather data.
  3. Make a request to Weather Underground to find Denver weather data.
  4. Print this data to the console in the form "The weather in Denver is <cloudy>" or similar.
  5. Test this to verify it works!

env.js

An env.js file is a great way to keep your API secret. We'll add our key to a seperate file, then list that file in our .gitignore, so that it's not pushed up to our remote repo.

  1. In your env.js file, turn your api key into a varible.
  2. Export that variable.
What would that file look like?

'use strict'

const apikey = "12345678";

module.exports = apikey;

3. Require it in `index.js`. 4. [.gitignore](https://help.github.com/articles/ignoring-files/) the env.js file. 5. Test that your weather request still works!

node-cli-weather's People

Contributors

zebgirouard avatar nickandersonr avatar jshawl avatar coreyselover avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.