What is the most efficient way of sending files between NodeJS servers?

谁说我不能喝 提交于 2019-11-30 10:10:24

There are plenty of ways to achieve this , but not so much to do it right !

socket io and wesockets are efficient when you use them with a browser , but since you don't , there is no need for it.

The first method you can try is to use the builtin Net module of nodejs, basically it will make a tcp connection between the servers and pass the data.

you should also keep in mind that you need to send chunks of data not the entire file , the socket.write method of the net module seems to be a good fit for your case check it : https://nodejs.org/api/net.html

But depending on the size of your files and concurrency , memory consumption can be quite large.

if you are running linux on both servers you could even send the files at ground zero with a simple linux command called scp

nohup scp -rpC /var/www/httpdocs/* remote_user@remote_domain.com:/var/www/httpdocs &

You can even do this with windows to linux or the other way.

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

the client scp for windows is pscp.exe

Hope this helps !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!