{"size": 823, "ext": "js", "max_stars_repo_path": "http-json-api-server.js", "max_stars_repo_name": "jdegand/learnyounode-exercises", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "http-json-api-server.js", "max_issues_repo_name": "jdegand/learnyounode-exercises", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "http-json-api-server.js", "max_forks_repo_name": "jdegand/learnyounode-exercises", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.71875, "max_line_length": 60, "alphanum_fraction": 0.6281895504}
const url = require('url');
const http = require('http');
const moment = require('moment');

const port = process.argv[2];

const server = http.createServer((req,res)=>{
  const { pathname, query } = url.parse(req.url, true);
  res.writeHead(200, {'Content-Type': 'application/json' });

  if(pathname === '/api/parsetime') {
    return res.end(JSON.stringify({
      hour: moment(query.iso).hour(),
      minute: moment(query.iso).minute(),
      second: moment(query.iso).second()
    }))
  }

  if(pathname === '/api/unixtime'){
    return res.end(JSON.stringify({
      unixtime: Number(moment(query.iso).format('x'))
    }))
  }
  res.writeHead(404, {'Content-Type': 'application/json'})
  res.end(JSON.stringify({
    success: false,
    message: `${pathname} is not a valid endpoint.`
  }))
})

server.listen(port);
