zoukankan      html  css  js  c++  java
  • 使用node.js 文档里的方法写一个web服务器

             刚刚看了node.js文档里的一个小例子,就是用 node.js 写一个web服务器的小例子

     上代码 (*^▽^*) 

     //helloworld.js
    // 使用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 helloworld.js ,然后将控制台显示的服务器运行地址复制到浏览器里,如果可以看到 Hello World 就表示服务器运行成功了(^-^)V

           感觉这段代码封装的很严实,逻辑很清晰,但是不知道应该怎么用(ಥ_ಥ),以后知道了再来更新吧(*^▽^*) 

  • 相关阅读:
    HOWTO re
    数据类型
    字符串
    最大公约数
    this
    tip 2:找最小公倍数之Boost
    tip 1:一个简单的将int型转换成char的方法
    Item47
    成员函数模板
    item44:将与参数无关的代码抽离template
  • 原文地址:https://www.cnblogs.com/codeofmine/p/9435521.html
Copyright © 2011-2022 走看看