Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Get Redirect Status Code From node-fetch

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

const fetch = require('node-fetch')

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

Returns `301`

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