K
K
Kostya Ostapuk2017-07-14 20:04:04
JavaScript
Kostya Ostapuk, 2017-07-14 20:04:04

Get NodeJS request?

I send a get request to localhost:3000/ using the server, I get a JSON file, how do I accept it and work with it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AntonDrelin, 2017-07-14
@AntonDrelin

More or less like this.

const url = ' http://...';

http.get(url,(res)=>{
  let body = '';
  res.on('data',(elem) => body +=elem);
  res.on('end',()=> console.log(JSON.parse(body));
});

R
RidgeA, 2017-07-14
@RidgeA

This is if without frameworks:
https://nodejs.org/api/http.html#http_class_http_i...
https://nodejs.org/api/stream.html#stream_class_st...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question