Home  >  Article  >  Web Front-end  >  Teach you how to use node.js to build a simple instant response server with detailed graphic and text explanations

Teach you how to use node.js to build a simple instant response server with detailed graphic and text explanations

黄舟
黄舟Original
2017-06-01 10:18:491502browse

This article mainly introduces the relevant information on how to build a simple instant response server using node.js. The introduction in the article is very detailed and has certain reference for everyone. Value, friends who need it, please follow the editor to learn it.

Preface

This article defaults to you having followed nodejs. If you don’t have installation, please install it. You can view this article for the installation tutorial. , without further ado, let’s take a look at the detailed introduction of this article.

The prerequisite is to create a front-end project

1. Create an html file and write the following content


What needs to be explained is /socket.io/socket.io.js This file server will generate usage methods in node_modules\socket.io\lib\socket.js

2. Create A js file (my file name is sock.js)


This js file is a file that needs to be run. The code in the file has comments

3. Run cmd to the front-end project you just created and execute npm install socket.io this command

Get this directory (it needs to be noted that sock.js and node_modules need to be in the same directory or may not be in the directory but I did not find the relevant documentation)

4. Continue to execute node sock.js This command then opens Enter the address http://localhost:8080/ in the browser and you will see the following screen


Enter any content to test it

Pay attention to the port number here Just now I have defined port 8080 in sock.js. I also need to open port 8080 in the browser

5. Test whether the data is really passed through the nodejs service


Data here

The following results are obtained

Indicates that the data is transmitted through the nodejs service

Summarize

The above is the detailed content of Teach you how to use node.js to build a simple instant response server with detailed graphic and text explanations. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn