Tag: Node.js

Read More
ECMAScript 6 in Node.js with Babel

Use ECMAScript 6 in Node.js with Babel

ECMAScript 6 is a great step for JavaScript. It provides some invaluable tools that make developing new code a bliss. If you want to learn about the features that ECMAScript 6 (also known as ECMAScript 2015, ES6 or ES2015), take a look at this two part series:

Unfortunately, Node.js will not let you use ES6 features out of the box. It does provide a way of using some of the ECMAScript 6 features, but not the whole thing. That’s what we are here to fix.

Read More
Create a Timestamp Microservice with Node.js

Create a Timestamp microservice with Node.js

This time around, we are going to be coding our own timestamp microservice using Node.js, and then, deploy it to Heroku. It’s going to be a very simple service that will return the unix time and natural date for the received input. Our API should be able to receive and properly handle the following two formats:

  • A unix timestamp is a metric used to track time by displaying the miliseconds (sometimes seconds) that have passed since January 1st, 1970 at 00:00:00 UTC. For a quick test, you can get the unix timestamp for right now, by going into the Chrome DevTools console and typing the following: Date.now();
  • The natural language date means that the date is passed in the following format: October 1, 2016.

Our timestamp microservice will accept any one of these two formats, and then, return a JSON object containing both formats. In other words:

  • If the API receives this: 1477388794872, it will output the following JSON object:
    {
      "unix": 1477388794872,
      "natural": "October 25, 2016"
    }
  • Receiving “October 25, 2016” will output the same exact JSON object.

If no unix timestamp nor natural date is present, we’ll return null for both fields:

{
  "unix": null,
  "natural": null
}
Read More
Build a wikipedia viewer with React, Babel and Webpack

Build a Wikipedia Viewer | The React Way

Today, we are going to build a Wikipedia viewer using React and Webpack in tandem. If you are not familiar with React at all, I recommend that you go through the introductory material first, it’ll save you a headache!

Additionally, we are going to be using ES6 class syntax for creating components, as this is the way React is heading towards. The previous tutorial in this series goes into more detail, so go ahead and take a look if you’d like. Let’s get our hands dirty then…

FCC Bonfire Series 132: Smallest Common Multiple

Math goodness for everyone today! We are going to be calculating the Smallest (or Least, or Lowest) Common Multiple of a range of numbers, as prompted by the Smallest Common Multiple bonfire. In mathematics, the least common multiple is the smallest positive number that is a multiple of two or more numbers (source).

As an example, take numbers 5 and 11. What is the smallest number divisible by the two? Let’s get the multiples of each and find out!

  • Multiples of 5: 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65…
  • Multiples of 11: 11, 22, 33, 44, 55, 66, 77, 88, 99…

As you can see, the first match we come across is number 55, that number is the least common multiple. We could try and use fancy math formulas to get it, but we are going to take advantage of our dear friend, the processor to take on the workload this time (at first). Today, I shall present you three different ways to achieve the same goal. One of them will be a more readable, short version, the second will be a little messy, but takes about half the time to come up with a solution. And the third will use some clever math and come up with the answer much faster! Interested? Let’s get to it.