啟動Nodejs服務

來源:互聯網
上載者:User

標籤:function   console   cnp   http   line   index   block   rap   try   

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.org4. 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/jointext/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‘ })

啟動Nodejs服務

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.