美文网首页
实战:npm天气预报工具

实战:npm天气预报工具

作者: 春木橙云 | 来源:发表于2017-06-02 12:16 被阅读35次

光学完没有,成果拿出来才有人信服!写一个小demo证明我学会了node基础~

package.json:

{
  "name": "node-weather12311",
  "version": "1.0.2",
  "description": "这是一简易的天气查询工具",
  "main": "index.js",
  "bin":{
    "weather":"./index.js"
    },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/HARRISKING/node-weather.git"
  },
  "keywords": [
    "weather"
  ],
  "author": "HARRISKING",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/HARRISKING/node-weather/issues"
  },
  "homepage": "https://github.com/HARRISKING/node-weather#readme",
  "dependencies": {
    "axios": "^0.16.1"
  }
}

index.js:

#!/usr/bin/env node

var axios = require('axios');
// console.log(process.argv);

var data = {};
if(process.argv[2]){
  data.params = {
    city: process.argv[2]
  }
}
axios.get('http://api.jirengu.com/weather.php',data)
.then(function(response){
  console.log('日期:'+response.data.results[0].weather_data[0].date)
  console.log('天气:'+response.data.results[0].weather_data[0].weather)
  console.log('风力:'+response.data.results[0].weather_data[0].wind)
  console.log('气温:'+response.data.results[0].weather_data[0].temperature)
  console.log('pm2.5:'+response.data.results[0].pm25)

}).catch(function(error){
  console.log('哎呀,出错了。。。')
})

结果:

这样,在下载之后,就可在通过输入“weather”查询此时当地的天气情况;
输入“weather + 地名”可以查询地名所在的天气状况。

成功!

相关文章

  • 实战:npm天气预报工具

    光学完没有,成果拿出来才有人信服!写一个小demo证明我学会了node基础~ package.json: inde...

  • vue 开始

    npm 工具 下载 npm 安装 vue, npm install vue 安装集成工具, npm install...

  • vue技术栈项目实战设计方案

    本篇文章基于实战下的线上项目,给出基于vue技术栈实现方案。 一、所需工具 npm:包管理工具,前端开发基本都会用...

  • NPM实战

    1.简介npm有两层含义。一层含义是Node的开放式模块登记和管理系统,网址为npmjs.org。另一层含义是No...

  • node.js中npm的使用

    npm(Node Package Manager) npm安装 安装node.js即有npm工具 npm用法 D:...

  • npm

    Npm: Node Package management node包管理工具;npm :Npm -v------n...

  • React+webpack

    开发工具准备好:npm+webpack+Visual Studio Code(编写工具)用npm(一个包管理工具,...

  • npm和npx的区别

    NPM-管理Node包的工具 NPX- 执行Node包的工具 npm5.2+支持NPX NPM本身实际上不能运行任...

  • 小程序,引入npm包后构建包,构建完成报错

    npm init 2. npm install xxx 3.工具=> 构建npm 解决: 全局搜索 compone...

  • nrm

    nrm(npm registry manager )是npm的镜像源管理工具 npm set registry h...

网友评论

      本文标题:实战:npm天气预报工具

      本文链接:https://www.haomeiwen.com/subject/zoxufxtx.html