1. Introduction
Front-end program apes are primarily concerned with the page, and you may not be able to use it at all. net,java,php and other background languages.
But the pages you make are always run, always tested. --that's the inevitable use of HTTP server. I used to use Visual Studio, although it is very useful, very powerful, but I developed a HTML, JavaScript, CSS, why use this silly big coarse things. Open once particularly slow, account for the memory is particularly strong, the installation of C disk to take up several G space.
Later, there was nothing to replace the Nodejs. instead of installing any plug-ins, you only need to manually create three small files (2KB in total), run and fast. The feeling is really very simple and light weight. share, know please skip, do not like to spray!
2. Four-step setup
The first step is to install Nodejs:
Not much nonsense, to www.nodejs.org download installation can.
Step two, create two JS files
Create two JS files, each saved as Server.js and Mine.js, with the following code:
Server.jsMine.js
I create a new "Demo1" folder on the desktop and copy the two created JS files into it.
Step three, create a. bat command file
or the "Demo1" folder, and then create a "startserver.bat" file in this folder, the contents of the file is actually a word:
Startserver.bat
At this point, there are three files in the Demo1 folder:
Fourth step, add your HTML file
or the "Demo1" folder, we need to create a "test1" folder in this file, and then we'll add a index.html and wait for the test.
The key point to note: Why is there a "test1" folder? Because the directory configured in our "Server.js" is "test1". If you look uncomfortable, you can get rid of it, but make sure the two names are the same.
If we have several test items in the Demo1, which one we need to run, it is very convenient to turn on "server.js" to modify the configuration.
3. One-click Start
After the "lengthy and complex" configuration process above, this step is simple.
How do I start with "one click"? Everyone should be able to guess.--startserver.bat--yes, double-click Run Startserver.bat and the console will prompt you for the HTTP Server service.
The port number defaults to "8080" and can be modified in "Server.js", just in the first line of code.
4. Create multiple HTTP servers
We talked about it for a long while, and we talked about how to create the first HTTP server, actually creating a second, third, fourth ... is as simple as that.
Take the three files in the Demo1 folder and test the location where you want to create the site. Open Server.js Modify the port number and directory name, run Startserver.bat.
If you want to create an HTTP server there, copy to where, and then run. Do not want to use the HTTP server again, directly delete the three files on the line.
Easy to use!
-------------------------------------------------------------------------------------------------------------
Please pay attention to my Weibo.
Also welcome to follow my tutorials:
" from design to model"" deep understanding of JavaScript prototype and closure series " "Microsoft petshop4.0 Source Interpretation Video" "Json2.js Source Interpretation video"
A rich text editor that supports inserting code--wangeditor
-------------------------------------------------------------------------------------------------------------
Use Nodejs to build the simplest and lightest HTTP server