Skip to content

Commit

Permalink
chore: added server file to node example
Browse files Browse the repository at this point in the history
  • Loading branch information
lquixada committed Jul 12, 2023
1 parent 748a312 commit 6890089
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions examples/node/index.js
@@ -1,14 +1,14 @@
const fetch = require('cross-fetch')

fetch('https://api.github.com/users/lquixada')
fetch('http://127.0.0.1:6000')
.then(res => {
if (res.status >= 400) {
throw new Error('Bad response from server')
}
return res.json()
})
.then(user => {
console.log(user)
.then(data => {
console.log(data)
})
.catch(err => {
console.error(err)
Expand Down
2 changes: 1 addition & 1 deletion examples/node/package.json
Expand Up @@ -6,6 +6,6 @@
"start": "node dist/bundle"
},
"dependencies": {
"cross-fetch": "*"
"cross-fetch": "4.0.0"
}
}
14 changes: 14 additions & 0 deletions examples/node/server.js
@@ -0,0 +1,14 @@
const http = require('http')

const hostname = '127.0.0.1'
const port = 6000

const server = http.createServer((req, res) => {
res.statusCode = 200
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify({ foo: 1 }))
})

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`)
})

0 comments on commit 6890089

Please sign in to comment.