分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

启动Nodejs服务

发布时间:2023-09-06 02:12责任编辑:傅花花关键词:jsNode

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‘
???})

启动Nodejs服务

原文地址:https://www.cnblogs.com/dqh123/p/9563044.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved