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

后端 未结 1 398
臣服心动
臣服心动 2021-01-01 01:30

Introduction

Say that on the same local network we have two Node JS servers set up with Express: Server A for API and Server F for form.

  • Server A is
相关标签:
1条回答
  • 2021-01-01 02:08

    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 !

    0 讨论(0)
提交回复
热议问题