美文网首页
2. 建立一个简单的服务器

2. 建立一个简单的服务器

作者: 论宅 | 来源:发表于2019-05-26 19:48 被阅读0次

    新建一个esayhttp.js,填上基本的内容:

    var http = require('http');
    http.createServer(function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write('<h1>Node.js</h1>');
    res.end('<p>Hello World</p>');
    }).listen(3000);
    console.log("HTTP server is listening at port 3000.");
    

    使用命令:

    git node easyhttp.js
    

    启动服务器
    打开浏览器,打开localhost:3000
    便可以看到结果

    相关文章

      网友评论

          本文标题:2. 建立一个简单的服务器

          本文链接:https://www.haomeiwen.com/subject/xfbftctx.html