admin管理员组文章数量:1025477
I'm trying to use node-fetch to do a GET request. I'm using dotenv to take the url, but the fetch retrieve me TypeError: Only absolute URLs are supported
, the URL_ENV
variable isn't undefined
require('dotenv').config();
let url = process.env.URL_ENV;
fetch(url ,{method: 'GET'}).then(response => {
return response.json()
})
I'm trying to use node-fetch to do a GET request. I'm using dotenv to take the url, but the fetch retrieve me TypeError: Only absolute URLs are supported
, the URL_ENV
variable isn't undefined
require('dotenv').config();
let url = process.env.URL_ENV;
fetch(url ,{method: 'GET'}).then(response => {
return response.json()
})
If I change the url variable with the content of the URL_ENV
inside the .env file it works
let url = "http://192.168.1.140:8080"
fetch(url,{method: 'GET'}).then(response => {
return response.json()
})
Share
Improve this question
asked May 23, 2019 at 12:16
SMattiaSMattia
491 gold badge1 silver badge6 bronze badges
8
- 1 Wele to Stack Overflow! Could you clarify you question? What is not working? What behavior do you expect? – Maris B. Commented May 23, 2019 at 12:22
- Thanks for you interest. I can't understand why putting the same url, in different way, I have two different behaviors. I'm expect that also with the env variable, the first snippet of code, the fetch works. – SMattia Commented May 23, 2019 at 13:53
-
1
Have you tried to check value of
process.env.URL_ENV
at run-time? Try to useConsole.log()
or similar method to find out the actual value. As the error says, it must be an absolute URL. – Maris B. Commented May 24, 2019 at 8:35 -
Yes I have tried,
http://192.168.1.140:8080
is printed – SMattia Commented May 24, 2019 at 9:01 -
3
If the code is not working with
process.env.URL_ENV
and suddenly works when you replace it with string literalhttp://192.168.1.140:8080
then there may be some unnecessary characters like spaces, tabs, newlines, etc.? – Maris B. Commented May 24, 2019 at 9:47
1 Answer
Reset to default 1Do you have mas or semicolon symbols at the end of your lines in .env file? If you do, remove them and it should work
I'm trying to use node-fetch to do a GET request. I'm using dotenv to take the url, but the fetch retrieve me TypeError: Only absolute URLs are supported
, the URL_ENV
variable isn't undefined
require('dotenv').config();
let url = process.env.URL_ENV;
fetch(url ,{method: 'GET'}).then(response => {
return response.json()
})
I'm trying to use node-fetch to do a GET request. I'm using dotenv to take the url, but the fetch retrieve me TypeError: Only absolute URLs are supported
, the URL_ENV
variable isn't undefined
require('dotenv').config();
let url = process.env.URL_ENV;
fetch(url ,{method: 'GET'}).then(response => {
return response.json()
})
If I change the url variable with the content of the URL_ENV
inside the .env file it works
let url = "http://192.168.1.140:8080"
fetch(url,{method: 'GET'}).then(response => {
return response.json()
})
Share
Improve this question
asked May 23, 2019 at 12:16
SMattiaSMattia
491 gold badge1 silver badge6 bronze badges
8
- 1 Wele to Stack Overflow! Could you clarify you question? What is not working? What behavior do you expect? – Maris B. Commented May 23, 2019 at 12:22
- Thanks for you interest. I can't understand why putting the same url, in different way, I have two different behaviors. I'm expect that also with the env variable, the first snippet of code, the fetch works. – SMattia Commented May 23, 2019 at 13:53
-
1
Have you tried to check value of
process.env.URL_ENV
at run-time? Try to useConsole.log()
or similar method to find out the actual value. As the error says, it must be an absolute URL. – Maris B. Commented May 24, 2019 at 8:35 -
Yes I have tried,
http://192.168.1.140:8080
is printed – SMattia Commented May 24, 2019 at 9:01 -
3
If the code is not working with
process.env.URL_ENV
and suddenly works when you replace it with string literalhttp://192.168.1.140:8080
then there may be some unnecessary characters like spaces, tabs, newlines, etc.? – Maris B. Commented May 24, 2019 at 9:47
1 Answer
Reset to default 1Do you have mas or semicolon symbols at the end of your lines in .env file? If you do, remove them and it should work
本文标签: javascriptTypeError Only absolute URLs are supported using env file with fetchStack Overflow
版权声明:本文标题:javascript - TypeError: Only absolute URLs are supported using env file with fetch - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745633568a2160306.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论