启动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'
})
posted @ 2018-08-30 22:14  往事随风_go  阅读(6080)  评论(0编辑  收藏  举报