-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8f923af
Showing
2,456 changed files
with
520,913 additions
and
0 deletions.
There are no files selected for viewing
Submodule myapp
added at
8f9b7a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// four=》nodedemo=》day01=>01.js | ||
//http 模块 | ||
// require 加载 引入 加载http模块 服务模块 | ||
var http=require("http") | ||
http.createServer(function(req,res){ | ||
// req=request请求 res=response 响应 | ||
// res.end结束响应 | ||
res.end("success") | ||
}).listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var http=require("http") | ||
// 创建服务器 | ||
http.createServer(function(req,res){ | ||
// res.end((1+2+3+4+5).toString()) | ||
// 解决中文乱码 | ||
res.writeHead(200,{"Content-type":"text/html;charset=UTF8"}) | ||
res.end("我爱中国") | ||
}).listen(3000) | ||
// listent监听端口 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var http=require("http") | ||
var fs=require("fs") //file system 文件系统 作用:操作文件 | ||
http.createServer(function(req,res){ | ||
// 响应头 | ||
res.writeHead(200,{"Content-type":"text/html;charset=utf8"}) | ||
if(req.url=="/"){ | ||
res.end("首页") | ||
}else if(req.url=="/red"){ | ||
// readfile 读文件 | ||
fs.readFile("./static/red.html",function(err,data){ | ||
res.end(data) | ||
}) | ||
}else if(req.url=="/green"){ | ||
fs.readFile("./static/green.html",function(err,data){ | ||
res.end(data) | ||
}) | ||
} | ||
}).listen(3000,function(){ | ||
console.log("listen挂起") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div>green</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body{ | ||
background:#f00 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<link rel="stylesheet" href="./red.css"/> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div>red</div> | ||
<img src=""/> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var http=require("http") | ||
// 创建服务器 | ||
http.createServer(function(req,res){ | ||
// req=request 请求 res=response 响应 | ||
// 结束响应 | ||
// res.end("success") | ||
// argument string buffer 缓存区 | ||
res.end((1+2+2+3).toString()) | ||
}).listen(3000) | ||
// 端口 localhost 本地 http://127.0.0.1:3000 dns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var http=require("http") | ||
//fs file system 文件系统 | ||
var fs=require("fs") | ||
http.createServer(function(req,res){ | ||
// 响应头 | ||
res.writeHead(200,{"Content-type":"text/html;charset=utf8"}) | ||
if(req.url=="/"){ | ||
res.end("首页") | ||
}else if(req.url=="/red"){ | ||
fs.readFile("./static/red.html",function(err,data){ | ||
res.end(data) | ||
}) | ||
}else if(req.url=="/green"){ | ||
fs.readFile("./static/green.html",function(err,data){ | ||
res.end(data) | ||
}) | ||
}else if(req.url=="/red.css"){ | ||
res.writeHead(200,{"Content-type":"text/css"}) | ||
fs.readFile("./static/red.css",function(err,data){ | ||
res.end(data) | ||
}) | ||
}else if(req.url=="/11.jpg"){ | ||
res.writeHead(200,{"Content-type":"image/jpg"}) | ||
fs.readFile("./static/11.jpg",function(err,data){ | ||
res.end(data) | ||
}) | ||
} | ||
// var type=req.url | ||
// switch(type){ | ||
// case "/": res.end("首页"); | ||
// case "/red": | ||
// fs.readFile("./static/red.html",function(err,data){ | ||
// res.end(data) | ||
// }); | ||
// case "/green": | ||
// fs.readFile("./static/green.html",function(err,data){ | ||
// res.end(data) | ||
// }); | ||
// } | ||
|
||
|
||
}).listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var http=require("http") | ||
http.createServer((req,res)=>{ | ||
// 解决favicon的问题 | ||
if(req.url=="/favicon.ico"){ | ||
return | ||
} | ||
res.end(req.url) | ||
}).listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var http=require("http") | ||
var url=require("url") | ||
http.createServer((req,res)=>{ | ||
res.writeHead(200,{"Content-type":"text/html;charset=utf8"}) | ||
if(req.url=="/favicon.ico"){ | ||
return | ||
} | ||
var obj=url.parse(req.url) | ||
console.log(obj) | ||
res.end("接收前端传输过的用户名为:"+obj.username) | ||
// if(req.url=="/send"){ | ||
// console.log("已经接收到前端发送的请求") | ||
// console.log(req) | ||
// res.end(req) | ||
// } | ||
}).listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// var http=require("http") | ||
var url = require("url") | ||
var query=url.parse(req.url,true).query | ||
// console.log(url) | ||
// resolve 转为字符串 第二个参数的路由会替换当前路径的一级路由 | ||
var obj=url.resolve("http://127.0.0.1:3000","/src") | ||
///b" | ||
// var obj = url.format("http:// 127.0.0.1:3000/a/c") | ||
// var obj = url.format({ | ||
// protocol: null, | ||
// slashes: null, | ||
// auth: null, | ||
// host: "http://127.0.0.1:3000", | ||
// port: "3000", | ||
// hostname: "http://127.0.0.1", | ||
// hash: null, | ||
// search: '?username=admin', | ||
// query: 'username=admin', | ||
// pathname: '/a/c', | ||
// path: '/a/c?username=admin', | ||
// href: '/a/c?username=admin' | ||
// }) | ||
// format 把对象转为字符串 | ||
console.log(obj) | ||
// http.createServer((req,res)=>{ | ||
|
||
// }).listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var http=require("http") | ||
var url=require("url") | ||
var fs=require("fs") | ||
http.createServer((req,res)=>{ | ||
var obj=url.resolve("http://127.0.0.1:3000","/green") | ||
var query=url.parse(obj,true) | ||
// obj=http://127.0.0.1:3000/red | ||
if(query.path=="/green"){ | ||
fs.readFile("./static/green.html",(err,data)=>{ | ||
res.end(data) | ||
}) | ||
}else if(query.path=="/blue"){ | ||
fs.readFile("./static/blue.html",(err,data)=>{ | ||
res.end(data) | ||
}) | ||
} | ||
}).listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// fs | ||
var http=require("http") | ||
var fs=require("fs") | ||
http.createServer((req,res)=>{ | ||
if(req.url=="/favicon.ico"){ | ||
return | ||
} | ||
// 读文件 readFile(url,options,callback) 异步 | ||
// fs.readFile("./static/1.txt",(err,data)=>{ | ||
// res.end(data) | ||
// }) | ||
// fs.readFileSync() 同步 | ||
// 写文件 writeFile(url,data,option,callback) | ||
// flag a append r read w write | ||
fs.writeFile("./static/2.txt","我是内容",{"flag":"a"},(err)=>{ | ||
if(err){ | ||
// throw 抛出 | ||
throw err | ||
} | ||
res.end("success") | ||
}) | ||
|
||
}).listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var http=require("http") | ||
var fs=require("fs") | ||
http.createServer((req,res)=>{ | ||
if(req.url=="/favicon.ico"){ | ||
return | ||
} | ||
// rename 改名 | ||
// fs.rename("./static/1.txt","./static/a.txt",(err)=>{ | ||
// if(err){ | ||
// throw err | ||
// } | ||
// res.end("success") | ||
// }) | ||
// unlink 删除文件 | ||
fs.unlink("./static/a.txt",(err)=>{ | ||
if(err){ | ||
throw err | ||
} | ||
res.end("success`") | ||
}) | ||
}).listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var http = require("http") | ||
var fs = require("fs") | ||
http.createServer((req, res) => { | ||
if (req.url == "/favicon.ico") { | ||
return | ||
} | ||
// 创建文件夹 mkdir | ||
// fs.mkdir("./static/aa",(err)=>{ | ||
// if(err){ | ||
// throw err | ||
// } | ||
// res.end("success") | ||
// }) | ||
// 删除文件夹 | ||
// fs.rmdir("./static/aa", (err) => { | ||
// if (err) { | ||
// throw err | ||
// } | ||
// res.end("success") | ||
// }) | ||
// 读取文件夹 readdir | ||
// fs.readdir("./static",(err,data)=>{ | ||
// if(err){ | ||
// throw err | ||
// } | ||
// res.end(data.toString()) | ||
// }) | ||
// 判断是否是文件夹 exists | ||
// fs.exists("./static/aa",(exists)=>{ | ||
// if(exists){ | ||
// console.log("文件夹已存在") | ||
// }else{ | ||
// fs.mkdir("./static/aa",(err)=>{ | ||
// res.end("success") | ||
// }) | ||
// } | ||
// }) | ||
// stat 判断是文件夹还是文件 | ||
fs.stat("./static/2.txt",(err,stats)=>{ | ||
// console.log(stats.isD irectory()) | ||
console.log(stats.isFile()) | ||
res.end("222") | ||
}) | ||
}).listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* 模块化 common | ||
* exports module.exports | ||
* require 引入 加载 | ||
* es6 | ||
* export export default | ||
* | ||
* import 导入 | ||
* exports和module.exports的区别? | ||
* 本身都是一个数组 | ||
* exports指向module.exports同时exports是module.exports的引用 | ||
* exports和module.exports默认是一个空对象 | ||
* node_modules 项目依赖 =》npm 包管理工具 | ||
*/ | ||
var bar=require("bar") | ||
console.log(bar) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
我是内容bfhdbghfj我是内容bfhdbghfj我是内容bfhdbghfj我是内容 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div>blue</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<form action="http://127.0.0.1:3000/send#a=1" method="get"> | ||
用户名:<input type="text" name="username"/> | ||
<input type="submit" value="提交"/> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<div>green</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body{ | ||
background:#f00 | ||
} |
Oops, something went wrong.