zoukankan      html  css  js  c++  java
  • [Node.js学习]初之体验

    创建服务器

    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!
    ');
    });
    server.listen(port,hostname,()=>{
        console.log(`服务器运行在http://${hostname}:${port}/`);
    });

    分析Node.js 的 HTTP 服务器:

    • 第一行请求(require)Node.js 自带的 http 模块,并且把它赋值给 http 变量。
    • 接下来我们调用 http 模块提供的函数: createServer 。这个函数会返回 一个对象,这个对象有一个叫做 listen 的方法,这个方法有一个数值参数, 指定这个 HTTP 服务器监听的端口号。

  • 相关阅读:
    函数的扩展
    数组的扩展
    event(1)
    面试
    iframes
    浏览器CSS兼容
    BFC
    简单的一个轮播效果
    asp.net identity 2.2.0 在WebForm下的角色启用和基本使用(二)
    我的web框架设计
  • 原文地址:https://www.cnblogs.com/hsd1727728211/p/6588407.html
Copyright © 2011-2022 走看看