Skip to content

Commit 6890089

Browse files
committed
chore: added server file to node example
1 parent 748a312 commit 6890089

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

examples/node/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const fetch = require('cross-fetch')
22

3-
fetch('https://api.github.com/users/lquixada')
3+
fetch('http://127.0.0.1:6000')
44
.then(res => {
55
if (res.status >= 400) {
66
throw new Error('Bad response from server')
77
}
88
return res.json()
99
})
10-
.then(user => {
11-
console.log(user)
10+
.then(data => {
11+
console.log(data)
1212
})
1313
.catch(err => {
1414
console.error(err)

examples/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"start": "node dist/bundle"
77
},
88
"dependencies": {
9-
"cross-fetch": "*"
9+
"cross-fetch": "4.0.0"
1010
}
1111
}

examples/node/server.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const http = require('http')
2+
3+
const hostname = '127.0.0.1'
4+
const port = 6000
5+
6+
const server = http.createServer((req, res) => {
7+
res.statusCode = 200
8+
res.setHeader('Content-Type', 'application/json')
9+
res.end(JSON.stringify({ foo: 1 }))
10+
})
11+
12+
server.listen(port, hostname, () => {
13+
console.log(`Server running at http://${hostname}:${port}/`)
14+
})

0 commit comments

Comments
 (0)