首页 > Web开发 > 详细

NodeJS

时间:2019-03-30 00:50:04      阅读:219      评论:0      收藏:0      [点我收藏+]

安装

https://nodejs.org/en/download/

自动启动工具

安装

npm install -g supervisor

启动

supervisor app.js

http模块

技术分享图片
const http = require(http)

http.createServer((req, res) => {
  res.writeHead(200,{Content-Type:text/html;charset=utf-8})
  res.end(Hello World!)
}).listen(3000)
View Code

我们可以看出NodeJS不及是一个应用还是一个HTTP服务器

url模块

url.parse()

技术分享图片
url.parse(http://localhost:3000)
Url {
  protocol: http:,
  slashes: true,
  auth: null,
  host: localhost:3000,
  port: 3000,
  hostname: localhost,
  hash: null,
  search: null,
  query: null,
  pathname: /,
  path: /,
  href: http://localhost:3000/ }
> url.parse(http://localhost:3000?name=Susan&age=18)
Url {
  protocol: http:,
  slashes: true,
  auth: null,
  host: localhost:3000,
  port: 3000,
  hostname: localhost,
  hash: null,
  search: ?name=Susan&age=18,
  query: name=Susan&age=18,
  pathname: /,
  path: /?name=Susan&age=18,
  href: http://localhost:3000/?name=Susan&age=18 }
> url.parse(http://localhost:3000?name=Susan&age=18, true)
Url {
  protocol: http:,
  slashes: true,
  auth: null,
  host: localhost:3000,
  port: 3000,
  hostname: localhost,
  hash: null,
  search: ?name=Susan&age=18,
  query: [Object: null prototype] { name: Susan, age: 18 },
  pathname: /,
  path: /?name=Susan&age=18,
  href: http://localhost:3000/?name=Susan&age=18 }
View Code

url.resolve()

技术分享图片
> url.resolve(http://localhost:3000, index)
http://localhost:3000/index
> url.resolve(http://localhost:3000/home, index)
View Code

 

NodeJS

原文:https://www.cnblogs.com/sonwrain/p/10624967.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!