JavaScript Node.js Basics Building a Command Line Application Making a GET Request with https

7,768 Points

Why am I getting a statusCode response of "404" instead of "200"?

I saw the other response to the same question, however I am using backticks and still receiving 404. Going to the URL directly works, so why is the statusCode still 404?

const https = require('https');

const username = 'ohtanya';

const request = https.get(`${username}.json`, (res) => {

3 Answers

28,400 Points

Do you have your profile set to private? I can't access your account though that URL either. Try going to the Privacy Settings and make sure the "Allow everyone to see your profile" checkbox is checked. If that is unchecked then your account will only be visible to yourself while logged in.

Since the NodeJS request does not include any login cookies the request will look like a regular non-logged in user, so the account has to be publicly accessible for the code to work.

Per Karlsson
Per Karlsson
12,678 Points

What @andren said. It's also easy to check if your profile is available by just pasting

in the URL bar.