lalicode

The code of Lali

Thoughts on Express.js and Heroku — lalicode

Thoughts on Express.js and Heroku

Nov. 13, 2016

I spent this weekend learning more about two very popular web development tools, Express and Heroku. The project I was working on was an image API using Express hosted on Heroku.



Here are my thoughts.

Express.js

I used Express.js with socket.io before to create chat rooms for an android app. I was amazed at how the whole back end was written in about 20 lines of code. In this project wanted a super simple web framework for the API so I went for Node.

Pros:

  • Setting up the web server is super easy! You can get everything running in very few lines of code
    
    var express = require('express');
    var app = express();
    
    ...
    
    var server = app.listen(8080, function () {
    
      var host = server.address().address
      var port = server.address().port
    
      console.log("Listening at http://%s:%s", host, port)
    
    })
  • Express.js has these things called middleware functions that can interact with requests, responses, and other middleware functions. The built in one for METHOD (GET, PUT, POST, DELETE) make writing REST APIs super easy.
  • It uses the Node.js Javascript environment, which is asynchronous. People love this because it can handle requests in parallel.
  • The simplicity allows writing small web applications a breeze.
  • It has a terrific package management system, npm.

Cons:

  • The Express generator is not newbie friendly. For those who do not know, the generator is used to create a skeleton for you application. It came with a HTML templating language called Jade (now Pub), which felt really unnecessary. I want to deploy a web application quickly not learn a new templating language!
  • It's not fully featured. You will need to use something like a MEAN stack, depending on your needs.
  • Node.js is not good for CPU intensive tasks

Heroku

I deployed my project on Heroku. The setup was okay, but could have been smoother. I forgot to provide a package.json file, which ended up causing deployment to not recognize the app as a Node.js. The bad thing is that Heroku did not tell me that and I had to look up the error on my own. They need more useful error messages.


Since my code was no longer in development, I had to change it to use Heroku's ports:


var server = app.listen(process.env.PORT, function () {

  var host = server.address().address
  var port = server.address().port

  console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);

})

Everything went pretty well after those two changes. Heroku provides nice usage graphs. It was easy to pick up and I got to deploy my application really quickly without having to do any Linux level configurations. You can also set your code to deploy on new pushes which is convenient. What I'm surprised to see was that you can deploy code from Dropbox. Git > Dropbox.


What I really appreciate is the fact that I didn't have to pay anything or sign up with my billing info to get hands-on experience with this service. I'm looking at you AWS.


You can try out the API by visiting https://memedb.herokuapp.com/emotes/Kappa. You can try it out with Kappa and 4head!


Add comment

No comments here yet, join the discussion!