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
lfkwtz
12,295 PointsGetting an "Unexpected identifier" error when trying to utilize my separate printer.js file
Getting this error:
/Users/leftynaut/Code/node/treehouse-profile/printer.js:12
module.exports.message = printMessage;
^^^^^^
SyntaxError: Unexpected identifier
When running this command:
node app.js chalkers davemcfarland leftynaut
Here is my app.js:
var profile = require("./profile.js");
var users = process.argv.slice(2);
users.forEach(profile.get);
Here is my profile.js:
// problem: we need a simple way to look at a user's badge count and JS points
// solution: use node.js to connect to Treehouse's API to get profile info to print out
var https = require('https');
var http = require('http');
var printer = require("./printer.js");
function get(username){
//Connect to the API URL (https://teamtreehouse.com/username.json)
var request = https.get("https://teamtreehouse.com/" + username + ".json", function(response) {
var body = "";
//Read the data
response.on('data', function(chunk) {
body += chunk;
});
response.on('end', function() {
if(response.statusCode === 200) {
try {
//Parse the data
var profile = JSON.parse(body);
//Print the data
printer.message(username,profile.badges.length, profile.points.JavaScript);
} catch(error) {
//Parse Error
printer.error(error);
}
} else {
//Status Code Error
printer.error({message: "There was an error getting a profile for " + username + ". (" + http.STATUS_CODES[response.statusCode] + ")"});
}
});
});
//Connection error
request.on('error', printer.error);
}
module.exports.get = get;
And here is my printer.js:
//Print out message
function printMessage(userName, badgeCount, points) {
var message = userName + ' has ' + badgeCount + ' total badge(s) and ' + points + ' points in JavaScript';
console.log(message);
}
//Print out error messages
function printError(error) {
console.error(error.message);
}
}
module.exports.message = printMessage;
module.exports.error = printError;
1 Answer
akak
29,446 PointsLooks like you have one extra bracket:
function printError(error) {
console.error(error.message);
}
} // bracket that might cause the error
lfkwtz
12,295 Pointslfkwtz
12,295 PointsYou're a lifesaver