Giter VIP home page Giter VIP logo

nodejs-weather-app's Introduction

Node Js Weather App

npm version npm Twitter

Node Js Weather App is a simple module for obtaining weather information.

Use as a CLI Tool

Prerequisite

You need to have NodeJS installed in your machine.

Add to CLI

  • Clone the repository.
  • Go to the repository folder and run the following command in your terminal:
npm link

Usage

Now you can just run the following in terminal:

weather

By default you'll get current weather of Dhaka City.

If you want to get weather of a different city, run:

weather -c CITY_NAME

Use as a Library

Installation

npm install nodejs-weather-app

Usage

This library exposes two methods:

  • getWeather, which will return a Promise
  • printWeather, which will show the output as a readable message

For example, you can use the library like this:

var nodejsWeatherApp = require('nodejs-weather-app');

nodejsWeatherApp.getWeather().then(val => {
	nodejsWeatherApp.printWeather(val);
});

If you don't specify any city and run the code, you will get Dhaka city temperature.

Output :

Current Temperature in Dhaka is 24.6°C

If you want to get specific city temperature, then pass the city name as a parameter of getWeather method:

var nodejsWeatherApp = require('nodejs-weather-app');

nodejsWeatherApp.getWeather('New York').then(val => {
	nodejsWeatherApp.printWeather(val);
});

Output :

Current Temperature in New York is 7.82°C

Basically, when the getWeather Promise will be resolved it will give a detailed weather object. So, you can easily modify it if necessary.

Like following:

var nodejsWeatherApp = require('nodejs-weather-app');

nodejsWeatherApp.getWeather().then(val => {
	printWeather(val);
});

function printWeather(weather) {
	let message = `Temperature in ${weather.name} is ${weather.main.temp}°C`;

	console.log(message);
}

If you want to see the full weather object, try this:

function printWeather(weather) {
	console.log(weather);
}

Output :

{
  "coord": {
    "lon": 85.17,
    "lat": 26.67
  },
  "weather": [
    {
      "id": 803,
      "main": "Clouds",
      "description": "broken clouds",
      "icon": "04n"
    }
  ],
  "base": "stations",
  "main": {
    "temp": 20.73,
    "pressure": 1016.99,
    "humidity": 92,
    "temp_min": 20.73,
    "temp_max": 20.73,
    "sea_level": 1023.25,
    "grnd_level": 1016.99
  },
  "wind": {
    "speed": 4.26,
    "deg": 98.5038
  },
  "clouds": {
    "all": 68
  },
  "dt": 1525197016,
  "sys": {
    "message": 0.002,
    "country": "IN",
    "sunrise": 1525131665,
    "sunset": 1525179120
  },
  "id": 1273043,
  "name": "Dhaka",
  "cod": 200
}

License

Node Js Weather App is open-sourced software licensed under the MIT license

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.