V
V
vladymyr_olegovich2016-06-14 21:22:11
Node.js
vladymyr_olegovich, 2016-06-14 21:22:11

How to do synchronous operations with file transfer over network in nodejs?

How to implement this chain synchronously (one after the other). I killed all evening, I can’t find anything (
-> Download a picture from a remote server
-> upload it to my server
-> send a picture to another server
-> get a response and make a return from the function in which this all happened.
If possible, directly count photos from one server and send them immediately to another - it will be even better :)
I'm not very familiar with the node, everything is easier in php :)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Taratin, 2016-06-14
@Taraflex

But why synchronously then? If it's about nice syntax, but take
https://www.npmjs.com/package/co
and get something like
Pseudocode

co(function*(){
    const imgBytes = yield downloadImageFromServer();
    const status  = yield uploadToAnotherServer(imgBytes);
    return status;
}).then( status => {
    console.log(status);
})

D
Dvorak, 2016-06-14
@allishappy

promises
middleware

Y
yusel, 2016-06-14
@yusel

and make a return from the function in which it all happened

This will not work, you need to do everything through callbacks :)
So use php, because. in comparison with it, emulation of sequential requests in a node will seem like terrible crutches.

D
de1m, 2016-06-15
@de1m

Monjo used the async module for this (the part about serial execution). Here
If necessary, I can add an example, but only tomorrow (example at work)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question