You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'use strict'
const http = require('http')
const URL = require('url').URL
const port = process.argv[2]
function convertISOTimeToJson(url) {
const date = new Date(url.searchParams.get('iso'))
if ('/api/parsetime' === url.pathname) {
return {
'hour': date.getHours(),
'minute': date.getMinutes(),
'second': date.getSeconds()
}
}
if ('/api/unixtime' === url.pathname) {
return {
'unixtime': date.getTime()
}
}
}
const server = http.createServer((request, response) => {
const url = new URL(`${request.scheme}://${request.host}${request.url}`)
const time = convertISOTimeToJson(url)
if ('GET' === request.method && time) {
response.writeHead(200, { 'Content-Type': 'application/json' })
response.write(JSON.stringify(time))
} else {
response.writeHead(404)
}
response.end()
})
server.listen(port)
$ learnyounode verify http-json-api-server.js
# LEARN YOU THE NODE.JS FOR MUCH WIN!
## HTTP JSON API SERVER (Exercise 13 of 13)
✗
Error connecting to
(http://localhost:44952/api/parsetime?iso=2020-03-06T19:37:36.894Z):
socket hang up
Your submission results compared to the expected:
────────────────────────────────────────────────────────────────────────────────
1. ACTUAL: "{\"hour\":20,\"minute\":37,\"second\":36}"
1. EXPECTED: ""
✗
Error connecting to
(http://localhost:44952/api/unixtime?iso=2020-03-06T19:37:36.894Z):
connect ECONNREFUSED 127.0.0.1:44952
2. ACTUAL: "{\"unixtime\":1583523456894}"
2. EXPECTED:
3. ACTUAL: ""
3. EXPECTED:
────────────────────────────────────────────────────────────────────────────────
✗
Submission results did not match expected!
# FAIL Your solution to HTTP JSON API SERVER didn't pass. Try again!
The text was updated successfully, but these errors were encountered:
http-json-api-server.js
$ learnyounode verify http-json-api-server.js
The text was updated successfully, but these errors were encountered: