启动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'
})
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值