Skip to content

Timestamp Microservice

Rafael J. Rodriguez edited this page May 17, 2016 · 2 revisions

Author

@Rafase282

Created by Rafase282

Github | FreeCodeCamp | CodePen | LinkedIn | Medium Blog/Site | E-Mail

Timestamp Microservice

Objective:

Build a full stack JavaScript app that successfully reverse-engineers this: http://votingapp.herokuapp.com/ and deploy it to Heroku.

Note that for each Basejump, you should create a new GitHub repository and a new Heroku project. If you can't remember how to do this, revisit http://freecodecamp.com/challenges/get-set-for-basejumps.

As you build your app, you should frequently commit changes to your codebase. You can do this by running git commit -am "your commit message". Note that you should replace "your commit message" with a brief summary of the changes you made to your code.

You can push these new commits to GitHub by running git push origin master, and to Heroku by running grunt --force && grunt buildcontrol:heroku.

User Stories:

  1. I can pass a string as a parameter, and it will check to see whether that string contains either a unix timestamp or a natural language date (example: January 1, 2016.
  2. If it does, it returns both the Unix timestamp and the natural language form of that date.
  3. If it does not contain a date or Unix timestamp, it returns null for those properties.

Links

Notes

I used Momentjs which is a library for dealing with time and many different formats.

Initially I was just using plain Date which is also fine, but you will have to make your own conversion for months, days and so on for the natural time.

I decided to create two functions that will convert from Unix to natural and from natural to Unix, then have a pair of check to handle the scenarios where the string given via url is Unix by checking if it is a number. Given that the Unix time is basically milliseconds passed since Jan 01 1970\. (UTC) till now it must be minimum 0 thus any negative number should return a null value. Likewise if the string does not parse to a number then it must be a natural date format, so I just had to check if it validates to a date with Momentjs.

Something that I learned from there unrelated to dates is how to get queries without requiring the ? in the url for APIs.

app.get('/:query', function(req, res) {
       var date = req.params.query;

the :query part is a variable name used to get whatever is after the / that can be accessed via the req.params as noted above.

I was also able to learn how to separate my API routes from the main routes which while not needed for this app, is something useful for more complex apps.

This is done by adding module.exports = function(app) { tot he file with the route and by requiring it on the server file like this var api = require('./app/api/timestamp.js');

Getting Started

  1. Welcome!
  2. Contact
  3. Get Started with Free Code Camp

Front End Development Certification

  1. HTML5 and CSS
  2. Responsive Design with Bootstrap
  3. Gear up for Success
  4. jQuery
  5. Basic JavaScript
  6. Object Oriented and Functional Programming
  7. Basic Algorithm Scripting
  8. Basic Front End Development Projects
  9. Intermediate Algorithm Scripting
  10. JSON APIs and Ajax
  11. Intermediate Front End Development Projects
  12. Claim Your Front End Development Certificate

Data Visualization Certification

  1. SASS
  2. React
  3. React Projects
  4. D3
  5. Data Visualization Projects
  6. Claim Your Data Visualization Certificate

Back End Development Certification

  1. Upper Intermediate Algorithm Scripting
  2. Automated Testing and Debugging
  3. Advanced Algorithm Scripting
  4. AngularJS (Legacy Material)
  5. Git
  6. Node.js and Express.js
  7. MongoDB
  8. API Projects
  9. Dynamic Web Applications
  10. Claim Your Back End Development Certificate

Full Stack Development Certification

  1. Greefield Nonprofit Project 1
  2. Greefield Nonprofit Project 2
  3. Legacy Nonprofit Project 1
  4. Legacy Nonprofit Project 2
  5. Claim your Full Stack Development Certification

Coding Interview Preparation

  1. Whiteboard Coding Interview Training
  2. Critical Thinking Interview Training
  3. Mock Interview 1
  4. Mock Interview 2
  5. Mock Interview 3
Clone this wiki locally