Skip to content

Commit d02de6a

Browse files
committed
learn: basic of server node.js
0 parents commit d02de6a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "rest-api-nodejs",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}

src/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createServer } from 'http'
2+
3+
const server = createServer((req, res) => {
4+
if (req.method === "GET" && req.url === "/") {
5+
res.statusCode = 200
6+
res.end()
7+
}
8+
})
9+
10+
server.listen(3001, () => {
11+
console.log("Server listen on http://localhost:3001")
12+
})

0 commit comments

Comments
 (0)