Most of the times I prefix fetch or node-fetch with an http://localhost
(to make it an absolute url).
import fetch from 'node-fetch';
fetch('http://localhost/whatever')
Is there any way of avoiding the localhost
part, other than simply placing localhost
in a variable?
const baseUrl = 'http://localhost';
fetch(`${baseUrl}/whatever`)
Very related to Superagent with absolute url prefix