Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ node statinquirer.js
- ? Which opponent do you choose? rat
- ? Which stat would you like to check? health
- connected as id 28
- RowDataPacket { health: 'health' }
- The rat's health is [object Object]
- // Load the NPM Package inquirer
- var inquirer = require("inquirer");
- var mysql = require("mysql");
- // Create a "Prompt" with a series of questions.
- inquirer
- .prompt([
- {
- type: "list",
- message: "Which opponent do you choose?",
- choices: ["rat", "goblin", "troll"],
- name: "opponent"
- },
- {
- type: "list",
- message: "Which stat would you like to check?",
- choices: ["health", "strength"],
- name: "stat"
- }
- ])
- .then(function(inquirerResponse) {
- var connection = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "",
- database: "esg_db"
- });
- connection.connect(function(err) {
- if (err) {
- console.error("error connecting: " + err.stack);
- return;
- }
- console.log("connected as id " + connection.threadId);
- });
- //*******************
- connection.query("SELECT '" + inquirerResponse.stat + "' FROM opponents WHERE name='"
- + inquirerResponse.opponent + "'" , function(err, result) {
- // We then begin building out HTML elements for the page.
- console.log(result);
- console.log("The " + inquirerResponse.opponent + "'s " + inquirerResponse.stat
- + " is " +
- result);
- });
- // connection.query("SELECT * FROM opponents", function(err, result) {
- // // We then begin building out HTML elements for the page.
- // console.log(result);
- // var answer = result;
- // console.log(result);
- // });
- // //this version works, so its not a problem with the connection
- //answer/result comes back undefined
- })
Add Comment
Please, Sign In to add comment