First of all, it is not my client playing griping at everything to play cross-border, and the code is not my writing, but I look for.
Directly on the code address, do not want to see the nagging directly download the code is OK.
Https://github.com/andygrn/Node.js-File-Server
After downloading the code, drag the server.js directly to the Node.exe icon to run, in the browser access http://127.0.0.1:80/can directly connect to the download server.
1, why should focus on the download server (file server)?
Because I want to write a multi-threaded breakpoint to continue the download library, of course, there is a server to test. Using Apache to build too much trouble, a mess of a lot of things to configure, before the use of simple Web server under the Internet. This is enough to satisfy the demand, but there are always some drawbacks, such as supporting only limited file extension formats, connection restrictions, and so on. And just when I think about node. js, which I have been focusing on for a while, I want to implement one myself, the code is in my hand, and a lot of things can be solved. And there will be server-related requirements, research is also good.
2. Why focus on node. js?
Originally I thought the server should use C + + to write, before the company also said that testing C # server performance is not good. But with the rise of the Hand tour, more and more examples show that the server can have a lot of solutions, as long as they like to use the right solution. Many tens of thousands of users of the hand tour server is written by PHP, Java, Go, Erlang also has a lot of success examples. We can see that, in a way, code-level efficiency is far less efficient than design and structure, not to mention that many people who write C + + do not necessarily write safe and efficient code.
node. js is a JavaScript solution. NetEase has also launched an open source distributed game Server engine pomelo based on node. js. And regardless of the specific code, the structure is still very beautiful, and because of the features of node. JS, it is inherently designed to solve high concurrency. node. JS is a Google V8-based, browser-free parsing JavaScript application with a very great number of third-party modules. Node. JS is designed to solve the problem of high-concurrency network servers. From this point of view, if you can solve the problem of large user connection from the angle of language or frame, then it is not necessary to use C + + to write a piece of crappy code and only support 800 people connection.
3. Is it convenient to use?
If you are familiar with the habit of asynchronous programming, others are very concise. After all, if a scripting language needs to be studied in order to write qualified code, it is the intention of the scripting language.
The overall server function is perfect, and the code volume is only about 200 lines.
File download server based on node. js