work hard work smart

专注于Java后端开发。 不断总结,举一反三。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

创建第一个应用Nodejs应用

Posted on 2022-02-18 13:03  work hard work smart  阅读(50)  评论(0编辑  收藏  举报

一、创建samp1.js

内容如下:

console.log("Hello World"); 

运行结果:

PS E:\study\nodejs\demo1> node .\samp1.js
Hello World

  

二、创建第一个应用

创建samp2.js

var http = require("http");

http.createServer(function(require, response){
    // 发送Http头部
    // HTTP状态值: 200: OK
    // 内容类型: text/plain
    response.writeHead(200,{'Content-Type': 'text/plain'});
    // 发送响应数据
    response.end("Hello World\n");
}).listen(8888);

console.log('server runing at http://127.0.0.1:8888/');

  

运行node .\samp2.js

访问 http://127.0.0.1:8888/