inotgo.com

Step 1 : About this tutorial   
Step 2 : node.js Introduce   
Step 3 : node.js The advantages of   
Step 4 : Open   
Step 5 : Download the installation package   
Step 6 : Install   
Step 7 : Verify successful installation   
Step 8 : The first application   
Step 9 : Server code server.js   
Step 10 : function   
Step 11 : Test   
Step 12 : Put the item in the upper right corner   

This site was originally mainly to explain java of , But tmall springboot The project requires vue.js, and vue.js Used in development vue-cli and webpack, Then you need to use node.js, So , Just do one by the way node.js Tutorial . I won't explain it in depth , Let's talk about simple introduction and Application .
What is? Node.js, as everyone knows javascript Is a scripting language that runs on the browser , Mainly used to control html Element , That is html dom Object , It's pure Client language .
Then interact with the server , You need to wait for the developers on the server , And the development of the server is based on java Mostly , For those who don't know java  Language front-end developers , Sometimes you have to wait for the server to be ready , Many times , Youth disappeared in such embarrassment .
So someone thought , If the server also uses javascript If you start writing , Isn't it easy for front-end personnel to develop things on the service side ? So a big man developed a v8 Engine , It runs on the server side javascript Language , On this basis, we have made some development , There is a server that can run javascript, It's called node.js Yes .
You can put node.js Simply look at javascript Written tomcat ...
Now that we have tomcat This is based on java Your server , Why should there be node.js And ?
1. node.js Applications on can use javascript development , This is convenient for front-end personnel
2. node.js of I/O The operation is non blocking , Compared to tomcat This kind of Blocking More advantages
It says , tanto , Next, let's make a node.js The server of , Experience
Step 5 :

Download the installation package

edit top fracture
node.js The official download address is :
https://nodejs.org/en/download/
But I already downloaded it , Put it in the upper right corner node-install.rar, There are 32 Bit and 64 Two versions of bit , Let you choose .
 Download the installation package
Installation has nothing to say .... Just go on to the next step
 Install
Step 7 :

Verify successful installation

edit top fracture
Run... First cmd , Then enter... In the console

node --version

The version number as shown in the figure appears , That means the installation is successful
 Verify successful installation
The above is installed node The environment , Then we will develop based on this .
First create a project and source file directory

e:\project\nodejs\src
 The first application
Then write the server code , stay src Create a new file server.js
1. introduce http modular

var http = require('http');

2. Prepare to process requests and responses service Function , It's like servlet In the doGet, doPost method .
this service The function does two things :
a. Set the return code 200, And the return format is text/plain
b. The returned content is : Hello Node.js

function service(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello Node.js');
}

3. be based on service Function to create a server

var server = http.createServer(service);

4. The server listens to 8088 port

server.listen(8088);
 Server code  server.js
var http = require('http'); function service(request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello Node.js'); } var server = http.createServer(service); server.listen(8088);
var http = require('http');
function service(request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end('Hello Node.js');
}
var server = http.createServer(service);
server.listen(8088);
Execute the following command

e:
cd e:\project\nodejs\src
node server.js

Start the server , And run just now server.js The code .
notes : Don't turn off the black screen .... Some students like to turn it off , Then he ran to ask why the browser can't access ...
 function
Access the address to test :

http://127.0.0.1:8088/
 Test
Step 12 :

Put the item in the upper right corner

edit top fracture
The project is compressed into nodejs.rar Put it in the upper right corner , There's nothing , It's just server.js , It is convenient for some students to write wrong by themselves , You can use the project I wrote .


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2021-02-27 Share an installation tutorial
hfnsc

https://www.cnblogs.com/zwjphp/p/14123746.html







The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2020-10-12 I want to ask edge Browser access http://127.0.0.1:8088/ No response , How to solve ?
zzqAND

I want to ask edge Browser access http://127.0.0.1:8088/ No response , How to solve ?




2 One answer

zzqAND
Answer time :2020-10-13
But Google or IE Just a browser

jjaa
Answer time :2020-10-12
Just change the port number



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see




2020-07-19 Beginners look confused
2020-06-02 I downloaded and installed the... In the upper right corner nodejs, It's just cmd Enter node --version, Show “ Not external or internal commands ......”
2020-05-11 I want to ask , Now it is necessary to change to node10 Are you , If you want to change , How to uninstall node and cnpm And


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 8 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about Front end part -node.js- introduction Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot