啟動Nodejs服務


vs code 中間創建

 1.  settings.json

{
"git.ignoreLimitWarning": true
}

 2. 

       1.   npm init       安裝pageage.json
       2.   npm install JQurey bootstrap 
3.  安裝 npm install -g cnpm --registry=https://registry.npm.taobao.org
4. node http服務
      1. require('http') //引入
      2. 創建http服務
      3. 接收發送響應請求 http.CreateServer
         Response.writeHead(200,{'Content-Type':'text/plain'}) //請求頭
         content-Type: text/html    //以html 返回
                text/plain  // 以原樣返回
text/join
text/xml

3. 

 

// 1. require('http')
var http = require( 'http')
var port = 8000
// 2. 通過http模塊創建http服務
var nodeServer = http. createServer( function( request, response) {
// 發送http頭部
// http 狀態值:200(成功) 400 500 401 402 403。。。 502 服務端的錯誤
response. writeHead( 200, {
'Content-Type': 'text/plain;charset=utf-8'
}) // 內容為text/plain
// 發送所響應的數據給客戶端
response. end( '你好第一個Nodejs')
})
nodeServer. listen(port, 'localhost', function( err) {
if (err)
throw err // 服務創建失敗,爆出錯誤
console. log( '服務創建成功!')
})

 4 .啟動

     PS D:\Nodejs\node-master\http> node index01.js
     服務創建成功!

 5.  http://localhost:8000/

   注意如果出現亂碼

 pasting

response. writeHead( 200, {
'Content-Type': 'text/plain;charset=utf-8'
})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM