Cannot recive jason data from url with node js





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I'm writing basic code from tutorial for node.js it should take json data from file that is on url location:https://jsonplaceholder.typicode.com/posts. and save it in a new file that is created with the same code.
My code is below



const https=require('https');
const fs=require('fs');
const url='https://jsonplaceholder.typicode.com/posts';
https.get('url', res => {

res.setEncoding('utf8');

let body='';

res.on('data', data => {
body += data;

});
res.on('end', ()=>{
fs.writeFile('data.json', body, 'utf8', (err)=>{
if(err) return err;
consle.log('data was saved');
});
});
});

It give me this error


https.js:235
throw new errors.Error('ERR_INVALID_DOMAIN_NAME');
^



Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name
at request (https.js:235:13)
at Object.get (https.js:249:15)
at Object.<anonymous> (C:ProjectsNodehttp-request.js:4:7)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)


Can anyone tell me where i,m wrong










share|improve this question


















  • 2





    You are doing the request to 'url', just remove those quotes

    – emed
    Nov 22 '18 at 23:19


















-1















I'm writing basic code from tutorial for node.js it should take json data from file that is on url location:https://jsonplaceholder.typicode.com/posts. and save it in a new file that is created with the same code.
My code is below



const https=require('https');
const fs=require('fs');
const url='https://jsonplaceholder.typicode.com/posts';
https.get('url', res => {

res.setEncoding('utf8');

let body='';

res.on('data', data => {
body += data;

});
res.on('end', ()=>{
fs.writeFile('data.json', body, 'utf8', (err)=>{
if(err) return err;
consle.log('data was saved');
});
});
});

It give me this error


https.js:235
throw new errors.Error('ERR_INVALID_DOMAIN_NAME');
^



Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name
at request (https.js:235:13)
at Object.get (https.js:249:15)
at Object.<anonymous> (C:ProjectsNodehttp-request.js:4:7)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)


Can anyone tell me where i,m wrong










share|improve this question


















  • 2





    You are doing the request to 'url', just remove those quotes

    – emed
    Nov 22 '18 at 23:19














-1












-1








-1








I'm writing basic code from tutorial for node.js it should take json data from file that is on url location:https://jsonplaceholder.typicode.com/posts. and save it in a new file that is created with the same code.
My code is below



const https=require('https');
const fs=require('fs');
const url='https://jsonplaceholder.typicode.com/posts';
https.get('url', res => {

res.setEncoding('utf8');

let body='';

res.on('data', data => {
body += data;

});
res.on('end', ()=>{
fs.writeFile('data.json', body, 'utf8', (err)=>{
if(err) return err;
consle.log('data was saved');
});
});
});

It give me this error


https.js:235
throw new errors.Error('ERR_INVALID_DOMAIN_NAME');
^



Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name
at request (https.js:235:13)
at Object.get (https.js:249:15)
at Object.<anonymous> (C:ProjectsNodehttp-request.js:4:7)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)


Can anyone tell me where i,m wrong










share|improve this question














I'm writing basic code from tutorial for node.js it should take json data from file that is on url location:https://jsonplaceholder.typicode.com/posts. and save it in a new file that is created with the same code.
My code is below



const https=require('https');
const fs=require('fs');
const url='https://jsonplaceholder.typicode.com/posts';
https.get('url', res => {

res.setEncoding('utf8');

let body='';

res.on('data', data => {
body += data;

});
res.on('end', ()=>{
fs.writeFile('data.json', body, 'utf8', (err)=>{
if(err) return err;
consle.log('data was saved');
});
});
});

It give me this error


https.js:235
throw new errors.Error('ERR_INVALID_DOMAIN_NAME');
^



Error [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name
at request (https.js:235:13)
at Object.get (https.js:249:15)
at Object.<anonymous> (C:ProjectsNodehttp-request.js:4:7)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)


Can anyone tell me where i,m wrong







javascript node.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 23:08









Alex_984gAlex_984g

1




1








  • 2





    You are doing the request to 'url', just remove those quotes

    – emed
    Nov 22 '18 at 23:19














  • 2





    You are doing the request to 'url', just remove those quotes

    – emed
    Nov 22 '18 at 23:19








2




2





You are doing the request to 'url', just remove those quotes

– emed
Nov 22 '18 at 23:19





You are doing the request to 'url', just remove those quotes

– emed
Nov 22 '18 at 23:19












1 Answer
1






active

oldest

votes


















0














https.get(url, res => {


instead of



https.get('url', res => {





share|improve this answer
























  • Thank you so much! I don't know how I haven't notice.

    – Alex_984g
    Nov 23 '18 at 12:42












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438933%2fcannot-recive-jason-data-from-url-with-node-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














https.get(url, res => {


instead of



https.get('url', res => {





share|improve this answer
























  • Thank you so much! I don't know how I haven't notice.

    – Alex_984g
    Nov 23 '18 at 12:42
















0














https.get(url, res => {


instead of



https.get('url', res => {





share|improve this answer
























  • Thank you so much! I don't know how I haven't notice.

    – Alex_984g
    Nov 23 '18 at 12:42














0












0








0







https.get(url, res => {


instead of



https.get('url', res => {





share|improve this answer













https.get(url, res => {


instead of



https.get('url', res => {






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 23:34









BlitzBlitz

11115




11115













  • Thank you so much! I don't know how I haven't notice.

    – Alex_984g
    Nov 23 '18 at 12:42



















  • Thank you so much! I don't know how I haven't notice.

    – Alex_984g
    Nov 23 '18 at 12:42

















Thank you so much! I don't know how I haven't notice.

– Alex_984g
Nov 23 '18 at 12:42





Thank you so much! I don't know how I haven't notice.

– Alex_984g
Nov 23 '18 at 12:42




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438933%2fcannot-recive-jason-data-from-url-with-node-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?