diff --git a/node/http-server/package.json b/node/http-server/package.json
new file mode 100644
index 0000000..e5c7ac4
--- /dev/null
+++ b/node/http-server/package.json
@@ -0,0 +1,11 @@
+{
+ "scripts": {
+ "start": "node src/index.js",
+ "dev": "nodemon src/index.js"
+ },
+ "devDependencies": {
+ "@types/node": "^14.0.5",
+ "@types/nodemon": "^1.19.0",
+ "nodemon": "^2.0.4"
+ }
+}
diff --git a/node/http-server/public/404.html b/node/http-server/public/404.html
new file mode 100644
index 0000000..79c3c90
--- /dev/null
+++ b/node/http-server/public/404.html
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+ Document
+
+
+ 404 Not Found
+
+ Home
+ About
+ 404
+
+
diff --git a/node/http-server/public/about.html b/node/http-server/public/about.html
new file mode 100644
index 0000000..d43ec04
--- /dev/null
+++ b/node/http-server/public/about.html
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+ Document
+
+
+ About Page
+
+ Home
+ About
+ 404
+
+
diff --git a/node/http-server/public/index.html b/node/http-server/public/index.html
new file mode 100644
index 0000000..95fe15f
--- /dev/null
+++ b/node/http-server/public/index.html
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+ Document
+
+
+ Home Page
+
+ Home
+ About
+ 404
+
+
diff --git a/node/http-server/public/style/style.css b/node/http-server/public/style/style.css
new file mode 100644
index 0000000..de116f5
--- /dev/null
+++ b/node/http-server/public/style/style.css
@@ -0,0 +1,3 @@
+html {
+ background-color: hsla(0, 70%, 70%, 0.3)
+}
diff --git a/node/http-server/src/index.js b/node/http-server/src/index.js
new file mode 100644
index 0000000..0107c5b
--- /dev/null
+++ b/node/http-server/src/index.js
@@ -0,0 +1,51 @@
+const path = require('path');
+const fs = require('fs');
+const http = require('http');
+
+// * ----------------
+
+const htmlFolder = path.resolve(__dirname, '../public');
+const notFoundPath = path.resolve(htmlFolder, '404.html');
+
+const getFilePath = (url) => {
+ const ext = path.extname(url);
+ const missingExt = ext ? '' : '.html';
+ const validUrl = url === '/' ? '/index' : url;
+ const filePath = htmlFolder + validUrl + missingExt;
+
+ return filePath;
+};
+
+const contentTypeMap = {
+ '.css': 'text/css',
+ '.html': 'text/html',
+};
+
+const getContentTypeHeader = (filePath) => ({
+ 'Content-Type': contentTypeMap[path.extname(filePath)] || '',
+});
+
+http
+ .createServer(async (req, res) => {
+ const filePath = getFilePath(req.url);
+
+ fs.readFile(filePath, (err, content) => {
+ if (err) {
+ if (err.code === 'ENOENT') {
+ fs.readFile(notFoundPath, (err, content) => {
+ res.writeHead(200, getContentTypeHeader(notFoundPath));
+ res.end(content, 'utf8');
+ });
+ } else {
+ res.writeHead(500);
+ res.end(`Server Error: ${err.code}`);
+ }
+ } else {
+ res.writeHead(200, getContentTypeHeader(filePath));
+ res.end(content, 'utf8');
+ }
+ });
+ })
+ .listen(8100, () => {
+ console.log('http://localhost:8100/');
+ });
diff --git a/node/http-server/tsconfig.json b/node/http-server/tsconfig.json
new file mode 100644
index 0000000..9e26dfe
--- /dev/null
+++ b/node/http-server/tsconfig.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/readme.md b/readme.md
index a4132d4..7ab71c0 100644
--- a/readme.md
+++ b/readme.md
@@ -1,4 +1,4 @@
-# LEARNING BY DOING
+# LEARN BY DOING
## What is it 这是什么
@@ -24,11 +24,13 @@ Because it's the only way to learn how to code -- by practice
- [ ] useful functions
- [ ] tricks
- [ ] polyfills
+ - **Node.js**
+ - [x] [http](./node/http-server/):搭建一个简单的服务器
- **JS lib usage**
- [x] [react hooks](./react/)
- [x] [redux](./redux/)
- [x] [rxjs](./rxjs/)
- - [ ] Webpack
+ - [x] [Webpack](https://github.com/seognil-study/webpack-playground)
- [**Testing**](./testing/)
- [x] [Jest](./testing/jest/)
- [x] [Testing-Library](./testing/testing-library/)