Screencast Build an Express.js App With TDD JavaScript

  • Gregg Pollack


  1. leeroywil said

    Cool video. Many tricks I learned. Thanks!

  2. Rogério Jun Nakatani said

    Great video! I learnt a lot of stuff with great details.

  3. Pedro Medeiros said

    Loved this screen cast. I'm already a veteran in the nodejs land. I build my first app in 2012 but its been a while since I touch in any express app. It's pretty nice to look at some tests approaches you guys have done. Gonna rewrite the tests of a nodejs app that I'm maintaining after watching this screencast. Just missed some table of content somewhere to jump straight to some parts. ='(

    Also loved the Carlos stickers. Plataformatec, GrokPodcast <3 <3 <3

  4. petersv said

    Beginner question here, why do I have to use __dirname + '/public' in the use.static to make it work, but you can just write the folder name?

  5. Faculty

    Carlos Souza said

    Good question, Peter. In our demo app, both should work (not sure about running on Windows, though). But due to the different ways we could run Node programs, using __dirname is actually the recommended way to access the file system. I've updated the demo app to reflect that. Thanks!

  6. petersv said

    Thanks for the clarification Carlos! :-)

  7. raghavtantry said

    Very informative video. Thanks a lot :)

  8. Pavel Bahro said

    What about a real life with MongoDB, AngularJS etc.? )

  9. CodeMunki9 said

    I keep getting the following errors (stuck at 0:59:45), and I can't figure out why:

    Creating new cities ✓ Returns a 201 status code 1) Return the city name 2) Return the city name

    7 passing (17ms) 2 failing

    1) Creating new cities Return the city name: TypeError: Cannot call method 'post' of undefined

    2) Creating new cities Return the city name: TypeError: Cannot call method 'post' of undefined

  10. Cyprian said

    Good to see your javascript workflow in practice. I noticed that you use less without syntax highlighting. You can easily setup source-highlight package to do it, for example. It is not big thing, but you know, it is just cool :)

  11. Faculty

    Carlos Souza said

    @CodeMunki9 it's hard to say without looking at your code, but my guess is that either the post function is being called on the wrong object or something weird is being assigned to app. If you can share your code with us using something like, that will make it easier to help.

  12. Faculty

    Carlos Souza said

    @Cyprian very cool! Thanks for the tip, I didn't know about that! :)

  13. CodeMunki9 said

    Nevermind, got it figured out, I got mixed up with a few directories. Thanks for your willingness to help out though!

  14. Brett Koenig said

    The reason that doesn't work on Heroku is because the free tier of RedisToGo only gives you 1 db. Since you only get one you can't select any DB other than 0.

  15. mateoclarke said

    I ran into an error early in the screencast (3:30) when installing express.

    When I tried: $ npm install express@4 --save

    I got this: npm ERR! Error: Invalid name: "BuildingBlocks"

    After googling for a bit, it seems that some versions on npm don't call caps in names of directories? I didn't really understand. What version of npm did you use here?

  16. Faculty

    Carlos Souza said

    @mateoclarke I've tested with npm versions 1.4.28 and 2.1.17, and it works fine. Which version are you using ? You might want to update to the latest npm with npm install npm -g. If you can't, feel free to edit the name entry in the file to suit your needs.

  17. Morgan Laco said

    Test (delete me)

  18. Jeff Wilson said

    I've been following along and my deploy heroku worked, but the app cannot start, logs are saying that /usr/bin/env: node : no such file or directory. My bin/www looks the same as yours? #!/usr/bin/env node. Is it because I'm running windows?

  19. Jeff Wilson said

    so I figured it out, pretty sure its because I didn't mark the file as executable, not sure how to do that on windows, so I changed the procfile to explicitly call node and now it works.

  20. Faculty

    Carlos Souza said

    @Odoyle glad you found a workaround! It is in fact because Windows doesn't know what /usr/bin/env is..

  21. LEGOMaster2 said

    @Odoyle How did you do that? I have the same problem.

  22. LEGOMaster2 said

    Never mind. I figured it out by moving to code from www to app.js and in the Procfile I wrote web:node app.js

  23. Student #372692 said

    This is a great video, but I'm having problems with the www file step. When I run it I get this:

    -bash: ./bin/www: /usr/bin/env_node: bad interpreter: No such file or directory

  24. Student #372692 said

    Doh...My error was the typo: Rogue '_' before node

  25. buffos said

    If someone is on windows and wants to follow with the NODE_ENV variable, you can do it as in the screencast, except the part where you define test-script in the package.json file. There you should just set test: "set NODE_ENV=test&& mocha test.js". Its important not to put any space before && before as i found out its included in the NODE_ENV variable (so you end up having NODE_ENV.length=5)

    As for www executing file, i just renamed it www.js, put it in the top folder and run node www.js . Not a big deal.

  26. jessica said

    After installing redis via npm and fixing up app.js to use redis instead of a static array, I get the following error for all my /client route tests: "Redis connection to failed - connect ECONNREFUSED"

    I have tried running 'redis-server' which is not recognized as a command and have installed redis-server via npm but their documentation is blank so my attempts at execution were just educated guesses that failed.

    Love this video and Express course btw!

  27. kingram said

    Hey guys, what's up with the lack of guidance on redis? That piece came at me absolutely out of nowhere, and I'm stalled following you because now I have to branch off to an entirely different mindset to figure out this piece.

    How about some guidance on redis?

  28. kingram said

    After getting redis-server going I was able to finish. Overall, this was a good intro for me because you offered some practical application. Also your mistakes were helpful because I was getting ahead of you in a couple of instances, and I did the exact same mistake and saw how to unwind it. Great examples of using test-driven development. I am not very familiar with that area, but through your examples, I have a new interest in reading up on testing methodology for future app development.

    Overall, very informative, succinct and packed with good info.

    thanks for sharing the knowledge.

  29. paulisloud said

    Really great screencast, learned a ton! Thanks guys.

  30. samjulien said

    You guys are getting good at these walkthrough videos. FYI, Redis isn't native on Windows, but there is a port for it. I wasn't able to get Hiredis installed, though. If any other Windows users out there were able to, I'd love some advice. Otherwise, great work guys.

  31. Federico Sananes said

    I don't understand, the setup, is he running a mac shell? I don't know how a mac shell looks like. He is just running all on the mac shell right?

  32. Federico Sananes said

    Why not doing this on a aws instance or similar, so that you can clone the ami setup and send it to the working team?

  33. Steve Schofield said

    I really enjoyed going through that video and really building on what I learned from the Building Blocks of Express course. Thanks!

  34. mikeyferg said


    I am getting a permission error with ./bin/www at 13:55.


    fs.js:439 return, stringToFlags(flags), mode); ^ Error: EACCES, permission denied '/Desktop/coding/node/express/codeschool/soupToBits/bin/www'

    Any guidance?

  35. LEGOMaster2 said

    @Kingram How did you get the redis server? I cannot.

  36. Faculty

    Carlos Souza said

    @mikeyferg can you tell me which version of Node is giving you this error ? Perhaps you have another service using port 3000, in which case you can try changing the port number on line 4 of bin/www

  37. Faculty

    Carlos Souza said

    To everyone having trouble with redis, this is a key/value store that needs to be running on your machine in order for the app to work. Sort of like a database. There are a couple different ways you can install redis, so I suggest you checkout What you install via npm is not redis itself, but the node redis client which connects to a redis server.

  38. Faculty

    Carlos Souza said

    @Federico Sananes that's a great suggestion to setup an aws instance. We'll talk about doing that for the next video. And about the shell I'm using.. it's just Bash on a Mac Terminal. Should be very (if not exactly) similar to Bash on a Unix.

  39. karebearhands said

    omg, burpee break!?!? that was surprising. haha

  40. Jerry Dilan Walters said

    Just FYI around 26 minutes in, where you mention "auto-testing" in ruby or using mocha, there's a pretty standard/ awesome way of doing that with node. T here's something called "nodemon" which you can install globally. It's super easy, and you just type $nodemon [filename] and it does all of that for you. That's what I have been using.

  41. Student #354622 said

    Enjoed that, and learnd a lot. Thx Carlos for all cool stuff on Express. Now its time for first backend builded on my own! :)

  42. ashleytemple said

    The Soup to Bit series is exactly what I was hoping to find after completing the courses! I don't work closely with many senior devs, so this is really useful to me to get pointed to best practices. For example, I had no idea there was a save-dev option for npm install, or that npm shrinkwrap existed. I, likely, would have eventually discovered them, but this is a much more effective way to get up to speed.

  43. sellabs1 said

    Hi, I'm following along, and at 32:56 you use '.expect(/cities/i)'. I was wondering, what does this regular expression test for?

  44. arti5m said

    I'm so happy I watched this. Next step is to follow along (and get up to speed with redis and heroku, of course).

  45. arti5m said

    Maybe vim too.

  46. saro_da said

    Where can I download the code from?

  47. Student #537033 said

    @sellabs1 Basically, it is CASE insensitive search of the word 'cities' within the html response.

  48. danieldram said

    Anywhere I could download the source code to follow along?

  49. danieldram said

    I couldn't get mocha -w to work on windows, mocha isn't recognized as a file or a command :/

  50. danieldram said

    Redis also isn't available on windows apparently? :/

  51. danieldram said

    @Saro, previous tab listed as "Source code"

  52. synox said

    Hi ! First of all, thx for the videos from France !

    Now i've a little question: i've followed the build for the bin/www file to be used with mocha

    But i've got this weird error : npm ERR! weird error 1 npm WARN This failure might be due to the use of legacy binary "node"

    I don't really know where does the problem come from... I've got everything up-to-date... Any Idea ?

    Thx again ! See ya

  53. synox said

    Hi again ! Just to say that i've find the solution...

    It was a bug in Ubuntu because there was a conflict with another package named node too. The nodejs package was named node and has been updated to nodejs. So just have to do a little ln -s nodejs node in the /usr/bin/ folder and done !

  54. Sam Ames said

    How does node know to serve up public/index.html when the user sends a get request to / ?

  55. Sam Ames said

    Oh right... The public dir is mounted on /

    So how does the following code in app.js mount it on / without mentioning '/' anywhere?


  56. Sam Ames said

    Oh I checked the api docs and found my answer: "app.use([path,] function [, function...]) Mounts the middleware function(s) at the path. If path is not specified, it defaults to “/”. ..."

    Awesome. Thanks for the walk-through - very helpful!

  57. Sam Ames said

    One way this could be improved is by using Dust, Handlebars or Jade instead of dragging in the JSON via JQuery... Just a thought.

  58. Sam Ames said

    ...Or ejs, like you have on the /cities/i pages :P

  59. Jeffrey Collins said

    Looking forward to viewing this video, but I am on windows; redis doesn't support windows. I know for mongo, there is mongolab. A website that you may use for your mondo database. Anything like that for redis?

  60. Jeffrey Collins said

    Where may I get a codeschool sticker like Carlos has on his laptop?

  61. Jeffrey Collins said

    roughly 12 minutes into the video Carlos creates a www file. What kind of file is it? js?

  62. Nikola Novakovic said

    Just a quick question, why did we encode our data into the URL ? Couldn't we just send it via JSON object ?

  63. Faculty

    Carlos Souza said

    For those interested in the source code for the application, here's the link:

  64. Faculty

    Carlos Souza said

    @havingfuncoding There's - The www file is just a JavaScript executable file without the .js extension.

  65. Faculty

    Carlos Souza said

    @Nikola The data is not encoded into the url, but rather using url encoded format. We did it this way just because it was the simplest way to do it at first. Using JSON is also a valid option, but would require us to specify the dataType on the $.ajax call as well as to use bodyParser.json instead of bodyParser.urlencoded

  66. johnalexander said

    You guys could have put "var app = require('./app');" after the "client.flushdb();" in the test.js... since your app already initially loading the database with the same 3 city keys.

  67. Zhernet said

    Love the burpee part ^^

  68. kys061 said

    Hi, i'm seeing this video, but i'm stopped by heroku..

    could you let me know where to learn heroku in this site?

  69. Jacob_Smith said

    Totally rockin' episode guys! I learned so much, even having built a node app or two previously. Thanks for all the hard work that goes into these; I think its stuff like this that takes codeschool and you guys above and beyond.

  70. Euklidian_Space said

    Stuck on 13:55. When I run ./bin/www I get the following error app.listen(3000, function(){ ^ TypeError: Object # has no method 'listen' at Object. (/home/data-kid/Desktop/code_school/express/building_blocks/bin/www:4:5) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:935:3

  71. Prima Aulia Gusta said

    Hi I can't run my . /bin/www somehow? Can anybody tell me what's wrong? I got this when i run . ./bin/www

    -bash: ./bin/www: line 3: syntax error near unexpected token (' -bash: ./bin/www: line 3:var app = require('./../server');'

  72. Prima Aulia Gusta said

    whoops. okay.. newbie mistakes. shouldn't have that extra period

  73. Nicholas Bester said

    @Carlos Wouldn't you run a check for empty fields on the client side to prevent any unnecessary calls to the server to reduce server load?

  74. latindigitalboy said

    woo!!! thanks!! this site is so amazing!!

  75. Paul Daniel said

    What were you drinking during this video Carlos, I want some...

  76. Thomas Strauß said

    Cool vid, I did the redis/express/node screencast before this one. This has much more focus on testing the express app. Very cool. I was missing this in the other vid.

  77. Steve Song said

    This demo should just focus on building app with express. Testing should be done on another video.

  78. alydawood said

    Can you add mongoDB on Heroku. Like You did for Redis ?

  79. Souma said

    What's that goofy sound when Carlos does a push to Heroku?

  80. Souma said

    I'm absolutely enthralled by the way Carlos uses vim. It would be really helpful if he used an app to display the keystrokes on the screen so we could see what shortcuts and commands he's using.

  81. johnryan1982 said

    Informative tutorial. Thanks guys

  82. kingcrabx9 said

    This is awesome so far. Carlos' VIM skills are enviable and I love the way he puts together the environment from scratch rather than bootstrapping it off a generator. Would be awesome to see him add Grunt and Livereload, ES6, Babel to the workflow but otherwise fantastic.

  83. kingcrabx9 said

    So I followed along but I used MongoDB with Mongoose instead of Redis. Highly recommend that if you guys really want to engage your brains a little harder without strictly following what Carlos is doing.

  84. Gonzalo Andres Vergara said

    This was a great screencast! Thanks.

  85. cdhelloworld said

    A++++ tutorial to exactly steps how we should build an Express App based upon test driver development. clear commits catches each points in flow with decent explanation, and easy to follow typing. A BIG THANKS~

  86. mankisun said

    Hi Carlos, It's nice video.I just tried to write test case.But when I tried for check json format . it gives the following error. Error: expected "Content-Type" of "application/json/", got "application/json; charset=utf-8"

    While I follow the same thing as you mention. it('Returns JSON format',function(done){

    request(app) .get('/projects') .expect('Content-Type', /json/, done);


  87. ronjp said

    I'm getting stuck while trying to follow along on windows, and the chmod command to make the bin/www file isn't being recognized by my cli. Is there another command for windows users?

  88. Gorbe99 said

    I am enjoying this video instruction, but it seems a bit awkward to me. There seems a bit of competition between these two presenters that's more than a little distracting.

About This Screencast

In this episode, we are going to take what we learned from Building Blocks of Express.js and build an application from the ground up. Carlos Souza and Gregg Pollack take the same application seen in the course and give it some new functionality. This includes adding tests and Redis, demonstrating how to use EJS, and finally incorporating some validations and deploying the application to Heroku.

You need to be an enrolled student in order to view this video and subscribe.

Enroll Now