JavaScript Node.js Basics 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,824 Points

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

1 Answer

Matthew Griffith
Matthew Griffith
Full Stack JavaScript Techdegree Student 20,984 Points

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