1. 程式人生 > >運行nodejs第一個程序

運行nodejs第一個程序

width resp reat 程序 ejs 接收 -type listen span

  • 環境

  node、webstrom、cmd

  • 步驟
  1. 打開Node.js環境

  window -->Node.js

  2.在webstrom編輯main.js文件

 1 /**
 2  * Created by Seadee on 2017/5/26.
 3  */
 4 
 5 //create the node.js application
 6     //step1 introduce the required module
 7     var http = require("http");
 8 
 9     //step2 create server
10     http.createServer(function
(request,response) { 11 //發送http狀態值、http頭部、內容類型 12 response.writeHead(200,{‘Content-Type‘:‘text/plain‘}); 13 //接收相應消息-->頁面打開後顯示 14 response.end(‘you are mine!‘); 15 }).listen(8889); //綁定端口 16 17 //cmd執行成功打印 18 console.log(‘Sever running at http://127.0.0.1:8889‘);

  3.在cmd執行main.js文件

  技術分享

  4.在瀏覽器打開(註意:這時不要關閉cmd,否則打不開!)

  技術分享

運行nodejs第一個程序