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功能

  • 相关阅读:
    web网络编程
    C++ 多线程*****(看书补充)
    C++信号处理
    预指令
    C++模板*******
    C++ 命名空间
    动态存储
    异常处理**********
    私钥、秘钥详解
    Pod控制器应用进阶
  • 原文地址:https://www.cnblogs.com/ataehee/p/13659950.html
Copyright © 2011-2022 走看看