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 Handling Errors in Node Handling Status Code Errors

TARIQ ALREHILY
TARIQ ALREHILY
14,822 Points

I am getting this on my Machine Terminal!!

SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at IncomingMessage.response.on (/Users/tariqalrehily/Desktop/Command_Line_Application/app.js:25:52) at IncomingMessage.emit (events.js:187:15) at endReadableNT (_stream_readable.js:1098:12) at process.internalTickCallback (internal/process/next_tick.js:72:19)

Paolo Scamardella
Paolo Scamardella
24,828 Points

Please provide some code examples. You may have a syntax error in your node app.

1 Answer

So, after a little googling, It seems that that particular response is saying that your trying to parse something that ISNT JSON. From the article I read, the "<" is a strong indicator that you are getting HTML data rather than valid JSON. The root cause is that the server returned HTML or some other non-JSON string. To see what is wrong, you can use console.log. With out the code, its hard to know exactly whats going on. Here is the link to the article I read. https://daveceddia.com/unexpected-token-in-json-at-position-0/

TARIQ ALREHILY
TARIQ ALREHILY
14,822 Points

Resolved, thanks for the article