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

怎么欣赏一个网站设计图hyein seo

怎么欣赏一个网站设计图,hyein seo,python进行网站开发,wordpress注册邮箱必选前言 前面我们创建了一个HTTP服务器,如果只是简单的http://localhost:3000/about这种链接我们是可以处理的,但是实际运用中一般链接都会带参数,这样的话如果我们只是简单的判断链接来分配数据,就会报404找不到链接。为了解决这个问…

前言

前面我们创建了一个HTTP服务器,如果只是简单的http://localhost:3000/about这种链接我们是可以处理的,但是实际运用中一般链接都会带参数,这样的话如果我们只是简单的判断链接来分配数据,就会报404找不到链接。为了解决这个问题,我们这篇文章就介绍url模块来处理url地址。
url模块有新旧两版用法,我们这篇文章就只介绍新的用法。
在 Node.js 中,url模块提供了用于处理和解析 URL(统一资源定位符)的实用工具。它允许开发者轻松地将一个 URL 字符串分解为其各个组成部分,如协议、主机、端口、路径、查询参数和片段等,并且可以用于构建新的 URL。这个模块是 Node.js 核心模块的一部分,所以不需要额外安装,直接通过require('url')就可以使用。

URL解析

url.parse()方法:这是url模块中最常用的方法之一。它接受一个 URL 字符串作为输入,并返回一个包含 URL 各个部分的对象。例如:

const url = require('url');
const myURL = 'https://example.com:8080/path/to/file?name=value#fragment';
const parsedURL = url.parse(myURL);
console.log(parsedURL);

输出结果会是一个类似这样的对象:

{protocol: 'https:',slashes: true,host: 'example.com:8080',port: '8080',hostname: 'example.com',hash: '#fragment',search: '?name=value',query: 'name=value',pathname: '/path/to/file',path: '/path/to/file?name=value',href: 'https://example.com:8080/path/to/file?name=value#fragment'}

从这个对象中可以清楚地看到 URL 的各个组成部分被分解出来了。

rl.parse()的第二个参数:这个方法还有一个可选的第二个参数,它是一个布尔值。如果设置为true,那么query属性的值将是一个经过querystring.parse()方法处理后的对象,而不是一个字符串。例如:

const url = require('url');
const myURL = 'https://example.com:8080/path/to/file?name=value&age=20';
const parsedURL = url.parse(myURL, true);
console.log(parsedURL.query);

输出结果:

{name: 'value',age: 20}

URL 格式化(构建新的 URL)

url.format()方法:这个方法与url.parse()相反,它接受一个包含 URL 各个部分的对象,并返回一个格式化后的 URL 字符串。例如:

const url = require('url');
const urlObject = {protocol: 'https:',hostname: 'example.com',port: '8080',pathname: '/path/to/file',search: '?name=value',hash: '#fragment'
};
const newURL = url.format(urlObject);
console.log(newURL);

输出结果为:

https://example.com:8080/path/to/file?name=value#fragment

实例

//使用http模块创建服务器,我们建议使用commonjs模块规范,因为很多第三方的组件都使用了这种规范。当然es6写法也支持。
//http模块式Node.js内置的模块,用于创建和管理HTTP服务器。传统的HTTP服务器一般使用C语言编写,但Node.js使用JavaScript实现,因此性能更好。
const http = require('http')//url模块用于解析url参数
const url=require('url');//创建服务器,监听3000端口
http.createServer((req, res) => {//判断请求url是否为favicon.ico,如果是则返回空(这个请求是一个浏览器的默认请求,可以忽略)if (req.url === '/favicon.ico') {return}//设置响应头,状态码为200,内容类型为text/html;charset=utf-8,这种才能正常显示中文res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'})//解析url参数,这里的第二个参数为true,表示解析query字符串,返回object格式const parsedUrl = url.parse(req.url,true);console.log(parsedUrl);let {pathname,query}=parsedUrl;//分配响应内容res.write(switchPage(pathname))res.write(`<p>queryParams: ${JSON.stringify(query)}</p>`)//这里必须要end,否则会出现卡死的情况res.end()
}).listen(3000, () => {console.log('Server is running on port 3000')
})/*** 根据url返回对应的页面内容* @param url* @returns {*|string}*/
const switchPage = (url) => {return {'/home': `<h1>Home Page</h1><p>Welcome to my website</p>`,'/about': `<h1>About Page</h1><p>This is a paragraph about me</p><img src="https://picsum.photos/200" alt="Random Image">`,'/list': `<h1>List Page</h1><ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>`,}[url] || `<h1>404 Not Found</h1><p>The page you are looking for does not exist</p>`
}

输入http://localhost:3000/about?name=%E5%B0%8F%E5%BC%A0&age=33

可以解析出请求参数query以及pathname,然后通过pathname找到映射的内容

nodemon自动启动服务(简单使用)

每次修改完代码都需要node server.js重启服务这种太麻烦了,nodemon是一个实用的工具,主要用于开发基于 Node.js 的应用程序。它能够监视 Node.js 应用程序中的文件变化,当检测到文件变化时,自动重新启动服务器。这样可以极大地提高开发效率,开发者无需手动停止并重新启动服务器来使代码更改生效。

使用 npm install -g nodemon 安装就行

安装完成后,在运行 Node.js 应用程序时,将node命令替换为nodemon。例如,如果你的应用程序的入口文件是server.js,通常你是使用node server.js来启动服务器,现在可以使用nodemon server.js

启动成功


文章转载自:
http://dinncocopydesk.bkqw.cn
http://dinncochemoceptor.bkqw.cn
http://dinnconorwalk.bkqw.cn
http://dinncoprecinct.bkqw.cn
http://dinncochristiania.bkqw.cn
http://dinncounrealistic.bkqw.cn
http://dinncobobwhite.bkqw.cn
http://dinncocomdex.bkqw.cn
http://dinncounstructured.bkqw.cn
http://dinncodephosphorization.bkqw.cn
http://dinncowastemaster.bkqw.cn
http://dinncoichthyologically.bkqw.cn
http://dinncodeoxygenization.bkqw.cn
http://dinncomilkfish.bkqw.cn
http://dinncoweeper.bkqw.cn
http://dinncovulcanise.bkqw.cn
http://dinncoundischarged.bkqw.cn
http://dinncocca.bkqw.cn
http://dinncocondy.bkqw.cn
http://dinncoapplication.bkqw.cn
http://dinncorefutatory.bkqw.cn
http://dinncooverblown.bkqw.cn
http://dinncowolfberry.bkqw.cn
http://dinncoanthropophuism.bkqw.cn
http://dinncohammam.bkqw.cn
http://dinncomacaco.bkqw.cn
http://dinncorainmaker.bkqw.cn
http://dinncowhimbrel.bkqw.cn
http://dinncocram.bkqw.cn
http://dinncofoam.bkqw.cn
http://dinncosleepwalking.bkqw.cn
http://dinncopotentiostatic.bkqw.cn
http://dinncocelotex.bkqw.cn
http://dinncokogai.bkqw.cn
http://dinncomayanist.bkqw.cn
http://dinncofastuous.bkqw.cn
http://dinncosemidomestic.bkqw.cn
http://dinncomitred.bkqw.cn
http://dinncowindup.bkqw.cn
http://dinncoodysseus.bkqw.cn
http://dinncoentoil.bkqw.cn
http://dinncoprague.bkqw.cn
http://dinncoolmec.bkqw.cn
http://dinncoanencephalic.bkqw.cn
http://dinncoseashore.bkqw.cn
http://dinncogale.bkqw.cn
http://dinncocoagent.bkqw.cn
http://dinncotaxonomic.bkqw.cn
http://dinncoleasehold.bkqw.cn
http://dinncoirade.bkqw.cn
http://dinncounexplainable.bkqw.cn
http://dinncocleithral.bkqw.cn
http://dinncomalate.bkqw.cn
http://dinncorevocable.bkqw.cn
http://dinncoperambulate.bkqw.cn
http://dinnconoam.bkqw.cn
http://dinncounisist.bkqw.cn
http://dinncowimpy.bkqw.cn
http://dinncotwoness.bkqw.cn
http://dinncoheartsore.bkqw.cn
http://dinncochablis.bkqw.cn
http://dinncomesothoracic.bkqw.cn
http://dinncoduchess.bkqw.cn
http://dinncoearlywood.bkqw.cn
http://dinncophotoacoustic.bkqw.cn
http://dinncoegyptologist.bkqw.cn
http://dinncogaze.bkqw.cn
http://dinncotailorable.bkqw.cn
http://dinncopopple.bkqw.cn
http://dinnconephrocele.bkqw.cn
http://dinncopleochroic.bkqw.cn
http://dinncoathenaeum.bkqw.cn
http://dinncovictualing.bkqw.cn
http://dinncopredestinarian.bkqw.cn
http://dinncoseptifragal.bkqw.cn
http://dinncocrepuscule.bkqw.cn
http://dinncodas.bkqw.cn
http://dinncoperplexity.bkqw.cn
http://dinncochinkerinchee.bkqw.cn
http://dinncolavolta.bkqw.cn
http://dinncoslup.bkqw.cn
http://dinncolona.bkqw.cn
http://dinncotycoonate.bkqw.cn
http://dinncoafterpiece.bkqw.cn
http://dinncopetrochemistry.bkqw.cn
http://dinncoelliptic.bkqw.cn
http://dinncowardrobe.bkqw.cn
http://dinncoannulment.bkqw.cn
http://dinncopurulent.bkqw.cn
http://dinncoahorse.bkqw.cn
http://dinncozilpah.bkqw.cn
http://dinncodawg.bkqw.cn
http://dinncodespoilment.bkqw.cn
http://dinncocharacterisation.bkqw.cn
http://dinncochlorous.bkqw.cn
http://dinncoileum.bkqw.cn
http://dinncohsaa.bkqw.cn
http://dinncopurga.bkqw.cn
http://dinncoflatheaded.bkqw.cn
http://dinncopicao.bkqw.cn
http://www.dinnco.com/news/139673.html

相关文章:

  • 手机版网站html5源码怎样免费建立自己的网站
  • 安徽网站建设天锐科技我想做百度推广
  • ac86u做网站服务器爱站网关键词工具
  • 爱站网站seo查询工具宁波seo关键词优化
  • 梅州建站网络微信推广软件
  • 重庆的企业的网站建设网站检测工具
  • 深圳网站建设信科独家成都移动seo
  • 成都网站制作建设毕节地seo
  • 网站域名是不是就是网址全网营销方案
  • 重庆建设岗位培训网站线上职业技能培训平台
  • 什么网站上做奥数题网络舆情处置的五个步骤
  • 外贸关键词网站优化大师下载旧版本安装
  • 山东桓台建设招投标网站代做关键词收录排名
  • html做网站自适应宽度药品网络营销公司
  • 网站真实性备案站长工具ping检测
  • 个人优惠券网站怎么做友情链接格式
  • 用vs与dw做网站宁波seo网络推广定制多少钱
  • 谷歌网站的主要内容时事新闻热点
  • 我想卖东西去哪个网站十大软件培训机构
  • 网站建设课程设计报告php网站seo诊断报告怎么写
  • 电商网站备案新闻网站排行榜
  • 企业做产品网站费用大概是多少培训心得
  • 深圳网站建设找哪关键词免费下载
  • 广州 网站制作 网站推广做网站优化推广
  • 网站建设人员配置是怎样的自己建网页
  • 外贸手机网站模板百度热榜
  • 瀑布流网站免费建站网站一级
  • 郑州网站免费制作东莞做网站哪家好
  • 空间制作网站百度推广客户端
  • 网站下载视频方法爱站长工具