JavaScript Node.js Basics 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}`;

function get(query) {
  const request= http.get(`${api.key}/conditions/q/CA/${query}.json`, response=> {


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
james south
Front End Web Development Techdegree Graduate 33,248 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,719 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!