zoukankan      html  css  js  c++  java
  • Node.js 学习记录 创建server初体验

    引用nodejs内置http模块,创建http server。

    // 直接引用内置http模块,直接写模块名即可
    const http = require('http')
    
    // 使用ES6规范,使用箭头函数
    const server = http.createServer((req,res) =>{
        res.writeHead(200, {'content-type' : 'text/html'})
        res.end('<h1> hello world!</h1>')
    })
    
    server.listen(3000, () => {
        console.log("listen on port 3000")
    })

    成功运行后,在浏览器访问http://localhost:3000,即可正常访问刚刚创建的网页。

    此外,还有更为精简版本

    // Lite version
    const http = require('http')
    const server = http.createServer((req, res) => {
        res.end('Hello world, Lite!')
    })
    
    server.listen('3000')

    此外,使用VSCODE,熟悉其内置git和debug功能

  • 相关阅读:
    day 06小结
    day 05小结
    day 05作业
    day 04作业
    day 03作业
    今日小结
    day 02小结
    hdu 4608 I-number(13多校#1 ,1009)
    zoj 2316 Matrix Multiplication(D)
    zoj 2316 Matrix Multiplication(2-D)
  • 原文地址:https://www.cnblogs.com/ataehee/p/13659950.html
Copyright © 2011-2022 走看看