ARTICLE AD BOX
I have a Node.js server which works as expected. I want to run a JS function that I used to trigger manually, via a website, on a daily basis. I extracted the function to a new file on the server in the same directory as the server file. When I run it, I get an error:
[TypeError: Failed to parse URL from /time] { [cause]: TypeError: Invalid URL at new URL (node:internal/url:819:25) at new Request (node:internal/deps/undici/undici:11063:25) at fetch (node:internal/deps/undici/undici:11988:25) at fetch (node:internal/deps/undici/undici:16555:10) at fetch (node:internal/bootstrap/web/exposed-window-or-worker:83:12) at update_ATC_ALC (/home/nfp-repo/login/daily_ATC_ALC_update.js:64:13) at Object.<anonymous> (/home/nfp-repo/login/daily_ATC_ALC_update.js:110:13) at Module._compile (node:internal/modules/cjs/loader:1811:14) at Object..js (node:internal/modules/cjs/loader:1951:10) at Module.load (node:internal/modules/cjs/loader:1532:32) { code: 'ERR_INVALID_URL', input: '/time' } 64 fetch('/time', options)If the above is not what I should use, how do I address the POST to the server?
64 fetch('http://localhost:80/time', options) // ?Versions:
Node.js v25.7.0 npm v11.11.0124k31 gold badges281 silver badges491 bronze badges
3651 gold badge3 silver badges12 bronze badges
1
you can't do relative paths for node js fetches, you have to use a actual url like the one you just showed
New contributor
guest is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1 Comment
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
2026-03-02T01:08:07.9Z+00:00
Explore related questions
See similar questions with these tags.
