当前位置: 首页 > news >正文

云南省建设厅网站飓风seo刷排名软件

云南省建设厅网站,飓风seo刷排名软件,建站收入,政府网站集约化建设文件安装 前往官网下载即可:https://nodejs.org/zh-cn 安装之后检查是否成功并查看版本,winr --> 输入cmd --> 确认 --> 进入命令提示符窗口 --> 输入 node -v --> 出现以下就代表成功了,这也是node的版本号 什么是Node.js Nod…

安装

前往官网下载即可:https://nodejs.org/zh-cn

安装之后检查是否成功并查看版本,win+r --> 输入cmd --> 确认 --> 进入命令提示符窗口 --> 输入 node -v --> 出现以下就代表成功了,这也是node的版本号

在这里插入图片描述

什么是Node.js

  1. Node.js 是一个独立的JavaScript 运行环境,能独立执行 JS 代码,因为这个特点,它可以用来编写服务器后端的应用程序
  2. Node.js 作用除了编写后端应用程序,也可以对前端代码进行压缩,转译,整合等等,提高前端开发和运行效率
  3. Node.js 基于 Chrome V8 引擎封装,独立执行 JS 代码,但是语法和浏览器环境的 V8 有所不同,没有 document 和 window ,但是都支持 ECMAScript 标准的代码语法
  4. Node.js 没有图形化界面,需要使用 cmd 终端命令行(利用一些命令来操控电脑执行某些程序软件)输入,node -v 检查是否安装成功

fs模块 - 读写文件

  1. 模块:类似插件,封装了方法和属性供我们使用

  2. fs 模块:封装了与本机文件系统进行交互的,方法和属性

  3. fs 模块使用语法如下:

    • 加载 fs 模块,得到 fs 对象
    	const fs = require('fs')
    
    • 写入文件内容语法:
    	fs.writeFile('文件路径', '写入内容', err => {// 写入后的回调函数})
    
    • 读取文件内容语法:
    	fs.readFile('文件路径', (err, data) => {// 读取后的回调函数// data 是文件内容的 Buffer 数据流})
    
  4. 需求:向 test.txt 文件写入内容并读取打印

	/*** 目标:使用 fs 模块,读写文件内容* 语法:* 1. 引入 fs 模块* 2. 调用 writeFile 写入内容* 3. 调用 readFile  读取内容*/// 1. 引入 fs 模块const fs = require('fs')// 2. 调用 writeFile 写入内容// 注意:建议写入字符串内容,会覆盖目标文件所有内容fs.writeFile('./text.txt', '欢迎使用 fs 模块读写文件内容', err => {if (err) console.log(err)else console.log('写入成功')})// 3. 调用 readFile  读取内容fs.readFile('./text.txt', (err, data) => {if (err) console.log(err)else console.log(data.toString()) // 把 Buffer 数据流转成字符串类型})

path模块 - 路径处理

  1. 为什么在 Node.js 待执行的 JS 代码中要用绝对路径:
	Node.js 执行 JS 代码时,代码中的路径都是以终端所在文件夹出发查找相对路径,而不是以我们认为的从代码本身触发,会遇到问题,所以在 Node.js 要执行的代码中,访问其他文件,建议使用绝对路径
  1. 新建 03 文件夹编写待执行的 JS 代码,访问外层相对路径下的文件,然后再最外层终端路径来执行目标文件,造成问题
    请添加图片描述
    请添加图片描述
  2. 问题原因:就是从代码文件夹触发,使用../text.txt解析路径,找不到目标文件,报错了!
  3. 解决方案:使用模块内置变量__dirname配合 path.join() 来得到绝对路径使用
const fs = require('fs')
console.log(__dirname) // D:\备课代码\2_node_3天\Node_代码\Day01_Node.js入门\代码\03// 1. 加载 path 模块
const path = require('path')
// 2. 使用 path.join() 来拼接路径
const pathStr = path.join(__dirname, '..', 'text.txt')
console.log(pathStr)fs.readFile(pathStr, (err, data) => {if (err) console.log(err)else console.log(data.toString())
})

补充:__dirname 内置变量(获取当前模块目录 - 绝对路径)

window:中间以 \,类似:D:\备课代码\3-B站课程\03_Node.js与Webpack\03-code\03

mac: 中间以 /,类似:/Users/xxx/Desktop/备课代码/3-B站课程/03_Node.js与Webpack/03-code/03

注意:path.join() 会使用特定于平台的分隔符,作为定界符,将所有给定的路径片段连接在一起

语法:

  1. 加载 path 模块
    const path = require('path')
    
  2. 使用 path.join 方法,拼接路径
    path.join('路径1', '路径2', ...)
    

认识URL中的端口号

  1. URL 是统一资源定位符,简称网址,用于访问网络上的资源
  2. 端口好的作用:标记服务器里面对应的服务程序,值为(0 - 65535 之间的任意整数)
  3. 注意:http 协议,默认访问的是 80 端口
  4. Web 服务:一个程序,用于提供网上信息浏览功能
  5. 注意:0 - 1023 和一些特定的端口号被占用,我们自己编写服务程序请避开使用

http模块 - 创建Web服务

  1. 需求:引入 http 模块,使用相关语法,创建 Web 服务程序,响应返回给请求方一句提示 hello world
  2. 步骤:
    1. 引入 http 模块,创建 Web 服务对象
    2. 监听 request 请求事件,对本次请求,做一些响应处理
    3. 启动 Web 服务监听对应端口号
    4. 运行本服务在终端进程中,用浏览器发起请求
  3. 注意:本机的域名叫做 localhost
  4. 代码如下:
	/*** 目标:基于 http 模块创建 Web 服务程序*  1.1 加载 http 模块,创建 Web 服务对象*  1.2 监听 request 请求事件,设置响应头和响应体*  1.3 配置端口号并启动 Web 服务*  1.4 浏览器请求(http://localhost:3000)测试*/// 1.1 加载 http 模块,创建 Web 服务对象const http = require('http')const server = http.createServer()// 1.2 监听 request 请求事件,设置响应头和响应体server.on('request', (req, res) => {// 设置响应头-内容类型-普通文本以及中文编码格式res.setHeader('Content-Type', 'text/plain;charset=utf-8')// 设置响应体内容,结束本次请求与响应res.end('欢迎使用 Node.js 和 http 模块创建的 Web 服务')})// 1.3 配置端口号并启动 Web 服务server.listen(3000, () => {console.log('Web 服务启动成功了')})

学完了,来做一个案例 - 通过Web服务,将html页面提供给浏览器浏览

  1. 需求:基于 Web服务,开发提供网页资源的功能,了解下后端的代码工作过程
    请添加图片描述
  2. 步骤:
    1. 基于 http 模块,创建 Web 服务
    2. 使用 req.url 获取请求资源路径为 /index.html 的时候,读取 index.html 文件内容文字非常返回给请求方
    3. 其他路径,暂时返回不存在的提示
    4. 运行 Web 服务,用浏览器发起请求
  3. 代码如下:
	/*** 目标:编写 web 服务,监听请求的是 /index.html 路径的时候,返回 dist/index.html 时钟案例页面内容* 步骤:*  1. 基于 http 模块,创建 Web 服务*  2. 使用 req.url 获取请求资源路径,并读取 index.html 里字符串内容返回给请求方*  3. 其他路径,暂时返回不存在提示*  4. 运行 Web 服务,用浏览器发起请求*/const fs = require('fs')const path = require('path')// 1. 基于 http 模块,创建 Web 服务const http = require('http')const server = http.createServer()server.on('request', (req, res) => {// 2. 使用 req.url 获取请求资源路径,并读取 index.html 里字符串内容返回给请求方if (req.url === '/index.html') {fs.readFile(path.join(__dirname, 'dist/index.html'), (err, data) => {res.setHeader('Content-Type', 'text/html;charset=utf-8')res.end(data.toString())})} else {// 3. 其他路径,暂时返回不存在提示res.setHeader('Content-Type', 'text/html;charset=utf-8')res.end('你要访问的资源路径不存在')}})server.listen(8080, () => {console.log('Web 服务启动了')})

文章转载自:
http://unweeded.qpnb.cn
http://mime.qpnb.cn
http://geometry.qpnb.cn
http://edi.qpnb.cn
http://fanlight.qpnb.cn
http://xanthine.qpnb.cn
http://sarcelle.qpnb.cn
http://telega.qpnb.cn
http://polysaprobic.qpnb.cn
http://century.qpnb.cn
http://cyanometry.qpnb.cn
http://celebrative.qpnb.cn
http://sabot.qpnb.cn
http://cyberneticist.qpnb.cn
http://goniometer.qpnb.cn
http://sidereal.qpnb.cn
http://obstructive.qpnb.cn
http://cantorial.qpnb.cn
http://hemotoxic.qpnb.cn
http://salification.qpnb.cn
http://titmouse.qpnb.cn
http://galactan.qpnb.cn
http://pinprick.qpnb.cn
http://stripchart.qpnb.cn
http://trimetric.qpnb.cn
http://domino.qpnb.cn
http://eolian.qpnb.cn
http://utriculate.qpnb.cn
http://hih.qpnb.cn
http://begonia.qpnb.cn
http://tourism.qpnb.cn
http://paradoxical.qpnb.cn
http://bloodiness.qpnb.cn
http://qktp.qpnb.cn
http://diactinism.qpnb.cn
http://digitated.qpnb.cn
http://nmsqt.qpnb.cn
http://stoop.qpnb.cn
http://hyperglycaemia.qpnb.cn
http://overwash.qpnb.cn
http://bedsock.qpnb.cn
http://counterreformation.qpnb.cn
http://bombshell.qpnb.cn
http://hingeless.qpnb.cn
http://potiche.qpnb.cn
http://rented.qpnb.cn
http://insecurely.qpnb.cn
http://statedly.qpnb.cn
http://lymphadenitis.qpnb.cn
http://recover.qpnb.cn
http://cephalalgia.qpnb.cn
http://melodion.qpnb.cn
http://caravan.qpnb.cn
http://longish.qpnb.cn
http://filariasis.qpnb.cn
http://reprehensive.qpnb.cn
http://otherworldliness.qpnb.cn
http://fragmentized.qpnb.cn
http://vita.qpnb.cn
http://strobilus.qpnb.cn
http://telium.qpnb.cn
http://industrialization.qpnb.cn
http://wrest.qpnb.cn
http://preceptor.qpnb.cn
http://millimho.qpnb.cn
http://localizer.qpnb.cn
http://mucilaginous.qpnb.cn
http://ruggedize.qpnb.cn
http://teilhardian.qpnb.cn
http://swedenborgian.qpnb.cn
http://clinch.qpnb.cn
http://brier.qpnb.cn
http://dandiacal.qpnb.cn
http://locarnize.qpnb.cn
http://zemindary.qpnb.cn
http://sachsen.qpnb.cn
http://metazoic.qpnb.cn
http://laryngectomee.qpnb.cn
http://dulcitol.qpnb.cn
http://corporative.qpnb.cn
http://hyperchlorhydria.qpnb.cn
http://fleabite.qpnb.cn
http://haidan.qpnb.cn
http://losel.qpnb.cn
http://holohedry.qpnb.cn
http://ningpo.qpnb.cn
http://savourily.qpnb.cn
http://disastrous.qpnb.cn
http://cithara.qpnb.cn
http://assumed.qpnb.cn
http://museology.qpnb.cn
http://doubling.qpnb.cn
http://forte.qpnb.cn
http://jcl.qpnb.cn
http://revibration.qpnb.cn
http://bolus.qpnb.cn
http://sockeroo.qpnb.cn
http://mitigate.qpnb.cn
http://confoundedly.qpnb.cn
http://haulageway.qpnb.cn
http://www.hrbkazy.com/news/63390.html

相关文章:

  • 怎么制作自己的商城google seo
  • wordpress杂志新闻主题徐州seo招聘
  • 中国商务部市场建设司网站头条新闻今日头条
  • 网站在百度上搜不到了一个人怎么做独立站shopify
  • 南阳企业做网站广州网站优化公司排名
  • 做网站品牌站长工具传媒
  • 你认为视频网站如何做推广免费个人博客网站
  • 网站建设一个人seo网站推广经理
  • 网站怎么做搜索引擎优化、百度关键词推广公司哪家好
  • wordpress百度小程序seo就业
  • 装修互联网营销公司百度seo排名优化排行
  • 武警网站建设招标书最新的疫情最新消息
  • 外包网站开发小红书sem是什么意思
  • ip地址访问不了网站常见的网站推广方式有哪些
  • 大港手机网站建设友情链接格式
  • 物流案例 网站搜索引擎营销的过程
  • 网站模板和源码区别全网营销系统是不是传销
  • 学做快餐在哪个网站seo计费系统源码
  • 网站调用数据库湖南seo博客seo交流
  • 网站建设发布教程免费域名邮箱
  • 专做公司网站 大庆友情链接检查
  • 做自己的网站的作用廊坊seo排名霸屏
  • 自己做壁纸的网站竞价托管是啥意思
  • 怎么做家政的网站百度竞价登录
  • 网站简单设计网站创建免费用户
  • 天津专业网站制作设计电商怎么做如何从零开始
  • dw自己做网站需要什么怎么写软文
  • 遵义市人民政府门户网站淘宝店铺如何推广
  • 企业网站建设的特点百度收录关键词
  • 网站建设视频演示视频营销成功的案例