Example of NodeJS with Geocoder, Inquirer, and Weather-js

First install your 3 dependencies in the same folder.

// Install Geocoder
$ npm install geocoder
// Install Inquirer
$ npm install inquirer
// Install WeatherJS
$ npm install weather-js

Then, you’ll need to have both userprompt.js, geocode.js and package.json in the same folder you are running the terminal command line from.

USERPROMPT.JS

The userprompt.js file should look like this:

var inquirer = require("inquirer");

inquirer.prompt([

  {
    type: "input",
    name: "name",
    message: "Who are you???"
  },

  {
    type: "list",
    name: "doingWhat",
    message: "What are you doing in my house??",
    choices: ["I made you cookies!", "No lie dude. I'm here to rob you.", "Uh. This is my house... Who are YOU???"]
  },

  {
    type: "checkbox",
    name: "carryingWhat",
    message: "What are you carrying in your hands??",
    choices: ["TV", "Slice of Toast", "Butter Knife"]
  },

  {
    type: "confirm",
    name: "canLeave",
    message: "Can you leave now?"
  },

  {
    type: "password",
    name: "myPassword",
    message: "Okay fine. You can stay. But only if you say the magic password."
  }

]).then(function(user) {

  
  if (user.myPassword === "myPassword") {

    console.log("==============================================");
    console.log("");
    console.log("Well a deal's a deal " + user.name);
    console.log("You can stay as long as you like.");
    console.log("Just put down the " + user.carryingWhat.join(" and ") + ". It's kind of freaking me out.");
    console.log("");
    console.log("==============================================");
  }
  else {

    console.log("==============================================");
    console.log("");
    console.log("Sorry " + user.name);
    console.log("I'm calling the cops!");
    console.log("");
    console.log("==============================================");

  }
});

the geocode.js file looks like this:

var geocoder = require("geocoder");
var inquirer = require("inquirer");
inquirer.prompt([
  {
    type: "input",
    name: "userInput",
    message: "Which location or landmark would you like to geocode?"
  }
]).then(function(location) {
  geocoder.geocode(location.userInput, function(err, data) {
    console.log(JSON.stringify(data, null, 2));
  });
});

Finally, run the following command, note that node does not require you to put the .js at the end of a file.

node userprompt

node geocode