Write a Web server using the methods in the node. JS Document

Source: Internet
Author: User

Just read a small example in the node. JS document, which is a small example of writing a Web server with node. js

On the code (*^▽^*)

Helloworld.js
Use node. js to write a server Const http=require (' HTTP '); const hostname= ' 127.0.0.1 ' const PORT=3000;CONST Server = Http.createserver (req,res) =>{ res.statuscode=200; Res.setheader (' Content-type ', ' text/plain '); Res.end (' Hello world\n ');}); Server.listen (Port,hostname, () =>{ console.log (' server running in http://${hostname}:${port}/');});

Then in the console input node Helloworld.js, and then the console display server run address copied to the browser, if you can see Hello world indicates that the server is running successfully (-^) V

Feel this piece of code encapsulation is very tight, logic is clear, but do not know how to use (?_?), later learned to update it (*^▽^*)

Write a Web server using the methods in the node. JS Document

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.