The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Get Redirect Status Code From node-fetch

TODO: Pull subtitle into page object

By default, node-fetch follows redirects and will return a 200 if the target page exists.

To get the status of the original page, set the `redirect` option to `manual`. For example:

code_start_default_section code_end_default_section

Returns `301`

If you want to see the status code of the final page after processing redirects, remove the option

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Get Redirect Status Code From node-fetch

-- p

By default, node-fetch follows redirects and will return a 200 if the target page exists.

-- p

To get the status of the original page, set the `redirect` option to `manual`. For example:

-- code/
-- javascript

const fetch = require('node-fetch')

fetch('https://www.alanwsmith.com/first-post-yeah-yeah', {
  redirect: 'manual',
}).then((res) => {
  console.log(res.status)
})

-- /code

-- p

Returns `301`

-- p

If you want to see the status code of the final page after processing redirects, remove the option


-- categories
-- JavaScript

-- metadata
-- date: 2021-11-26 22:17:14
-- id: 21u5smjn
-- status: scratch
-- type: post
-- SCRUBBED_NEO: false
-- site: aws