fix(guide): Fix all frontmatter
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
##localeTitle: undefined
|
||||
文件系统
|
||||
---
|
||||
title: File System
|
||||
localeTitle: 文件系统
|
||||
---
|
||||
## 文件系统
|
||||
|
||||
Node.js文件系统模块允许您使用计算机上的文件系统。
|
||||
|
||||
@@ -8,7 +11,7 @@ Node.js有一组内置模块,无需进一步安装即可使用。类似地,
|
||||
要包含模块,请使用`require()`函数和模块名称。
|
||||
|
||||
```javascript
|
||||
const fs = require('fs');
|
||||
const fs = require('fs');
|
||||
```
|
||||
|
||||
文件系统模块的常用用法:
|
||||
@@ -26,15 +29,15 @@ const fs = require('fs');
|
||||
Node.js代码从您的计算机读取文件并将内容返回到控制台。
|
||||
|
||||
```javascript
|
||||
const fs = require('fs');
|
||||
fs.readFile('input.txt', 'utf-8', (err, data) => {
|
||||
if(err){
|
||||
console.log(err);
|
||||
}
|
||||
else{
|
||||
console.log("Content present in input.txt file : " + data.toString());
|
||||
}
|
||||
});
|
||||
const fs = require('fs');
|
||||
fs.readFile('input.txt', 'utf-8', (err, data) => {
|
||||
if(err){
|
||||
console.log(err);
|
||||
}
|
||||
else{
|
||||
console.log("Content present in input.txt file : " + data.toString());
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
上面的代码从您的计算机读取文件_input.txt_并将内容返回到控制台。
|
||||
@@ -55,15 +58,15 @@ _注意_ :input.txt文件应该存在于Node.js代码文件所在的同一目
|
||||
Node.js代码将内容写入文件。
|
||||
|
||||
```javascript
|
||||
const fs = require('fs');
|
||||
fs.writeFile('output.txt', "New content added", (err, data) => {
|
||||
if(err){
|
||||
console.log(err);
|
||||
}
|
||||
else{
|
||||
console.log("The file is saved");
|
||||
}
|
||||
});
|
||||
const fs = require('fs');
|
||||
fs.writeFile('output.txt', "New content added", (err, data) => {
|
||||
if(err){
|
||||
console.log(err);
|
||||
}
|
||||
else{
|
||||
console.log("The file is saved");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
上面的代码创建了一个文件_output.txt_并添加了_添加_到其中的_新内容_ 。
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
##localeTitle: undefined
|
||||
HTTP
|
||||
---
|
||||
title: HTTP
|
||||
localeTitle: HTTP
|
||||
---
|
||||
## HTTP
|
||||
|
||||
Node.js有一组内置模块,无需进一步安装即可使用。类似地, **HTTP模块**包含通过超文本传输协议(HTTP)传输数据所需的一组功能。
|
||||
|
||||
@@ -8,7 +11,7 @@ HTTP模块可以创建一个HTTP服务器,该服务器侦听服务器端口并
|
||||
要包含模块,请使用`require()`函数和模块名称。
|
||||
|
||||
```javascript
|
||||
const http = require('http');
|
||||
const http = require('http');
|
||||
```
|
||||
|
||||
## Node.js作为Web服务器
|
||||
@@ -16,16 +19,16 @@ const http = require('http');
|
||||
`createServer()`方法用于创建HTTP服务器。 `res.writeHead()`方法的第一个参数是状态代码, `200`表示一切正常,第二个参数是包含响应头的对象。
|
||||
|
||||
```javascript
|
||||
const http = require('http');
|
||||
|
||||
//create a server object:
|
||||
http.createServer((req, res) => {
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.write('Hello World!'); //write a response to the client
|
||||
res.end(); //end the response
|
||||
}).listen(8000); //the server object listens on port 8000
|
||||
|
||||
console.log("Server is listening on port no : 8000");
|
||||
const http = require('http');
|
||||
|
||||
//create a server object:
|
||||
http.createServer((req, res) => {
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.write('Hello World!'); //write a response to the client
|
||||
res.end(); //end the response
|
||||
}).listen(8000); //the server object listens on port 8000
|
||||
|
||||
console.log("Server is listening on port no : 8000");
|
||||
```
|
||||
|
||||
### 执行步骤:
|
||||
|
||||
Reference in New Issue
Block a user