In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge points about how to create Node.js applications. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Step 1 of creating Node.js application: introduce required module
We use the require instruction to load the http module and assign the instantiated HTTP to the variable http. The example is as follows:
Var http = require ("http"); step 2: create a server
Next we create the server using the http.createServer () method and bind port 8888 using the listen method. The function receives and responds to data through request and response parameters.
As an example, create a file called server.js in the root directory of your project and write the following code:
Var http = require ('http'); http.createServer (function (request, response) {/ / send HTTP header / / HTTP status value: 200: OK / / content type: text/plain response.writeHead (200, {' Content-Type': 'text/plain'}); / / send response data "Hello World" response.end (' Hello World\ n');}) .response (8888) / / the terminal prints the following information console.log ('Server running at http://127.0.0.1:8888/');
We have completed a working HTTP server with the above code.
Use the node command to execute the above code:
Node server.jsServer running at http://127.0.0.1:8888/
Next, open a browser to visit http://127.0.0.1:8888/, and you will see a web page that says "Hello World".
Analyze the HTTP server for Node.js:
The first line requests (require) the http module that comes with Node.js and assigns it to the http variable.
Next we call the function provided by the http module: createServer. This function returns an object that has a method called listen, which takes a numeric argument that specifies the port number that the HTTP server listens to.
These are all the contents of the article "how to create Node.js applications". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.