Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics 2017 Create a Command Line Weather Application Retrieving Data - Solution

Nikola Jankovic
Nikola Jankovic
10,793 Points

Can not require api.json

const http= require("http");
const query="london";
const api= require('./api.json');

function printMessage(city, temperature , airPresure) {
  const string= `In ${city} temperature is ${temperature} and air resure is ${airPresure}`;
  console.log(string);
};

function get(query) {
  const request= http.get(`http://api.wunderground.com/api/${api.key}/conditions/q/CA/${query}.json`, response=> {
    console.log(response.statusCode);
  });
};

get(query);

This is my api.json file

{
  "key:" "2ea73291ffd35eca"
}

error message in the console is "Unexpected string in JSON at pos ition 12"???

3 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you have the colon that should separate the key : value pair inside the string "key", so you don't actually have a key : value pair in your json. the key is "key", not "key:"

Ken S.
Ken S.
3,838 Points

This indirectly helped me so I'll share an additional detail:

The quotes MUST be double quotes. I used single quotes and it did not work. I vaguely recall this being mentioned perhaps in AJAX but it still crept up on me!