0

I'm trying to compare 2 URLs, which should be identical, however for some reason I'm getting there's some difference. I'm wondering if there's something fundamental I'm misunderstanding with NPM fetch.

Here's my example code:

const fetch = require('node-fetch');

let startingPageBase = await fetch('https://www.example.com')
let startingPage = await startingPageBase.text()

let currentPageBase = await fetch('https://www.example.com')
let currentPage = await currentPageBase.text()

if (startingPageBase === currentPageBase) {
   console.log('Checked ')
} else {
   console.log('Not the same')
}

I'm basically trying to check if the HTML of the 2 pages is the same.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
userMod2
  • 8,312
  • 13
  • 63
  • 115
  • Also, don't forget to wrap your `await`s in to an async function. You can't use `await` outside of async functions, but your browser console or IDE probably already told you that. – Nano Miratus Mar 31 '20 at 13:44

1 Answers1

2

You are comparing the two promises, not the actual text values.

do this:

if (startingPage === currentPage) {
  console.log('Checked ')
} else {
  console.log('Not the same')
}
Nano Miratus
  • 467
  • 3
  • 13