Jumpstart to Node.js

Jumpstart to Node.js

From APIs to Microservices to Full Stack applications, Node.js continues to grow in popularity. If you’re just starting to learn the platform, you can be easily overwhelmed and confused on how and where to start.  

I created this egghead.io playlist to get you up and productive as fast as possible. Even with the playlist, I thought some additional background material might help even more, which brings you to this page. Here I list every lesson in the playlist, tell you what you’ll learn in that lesson and why I think it’s important. Use the link to the playlist above or click the image next to each description below to go straight to that lesson.

After finishing this playlist, I feel like you’ll have the necessary skills to take on your own node.js project, dive into someone else’s as a contributor, or contribute to Node.js itself!

Disclaimer: Some of the lessons are available to egghead.io subscribers only. I’ll indicate that on each lesson below. I’ll also try to include links to relevant free content where possible. Finally, some of these lessons were recording for older versions of Node.js. There may be some differences in current versions of Node.js, but I’ve tried not to include anything that is no longer true.

Jumpstart to Node.js

Installing Node.js and NPM on Windows

Spoiler Alert! Before using Node.js, you will have to get it installed on your system! In this first lesson in the series, Lucas Ruebbelke shows us how to get Node.js and NPM installed on a Windows computer. There is some good overview info in here, even though it covers an older version of Node.js. OS X/Linux folks should use NVM (see next lesson below).

Trying new versions of Node.js with NVM

PRO At any given time, you will encounter multiple versions of Node.js. For personal projects, you may want to use the latest, bleeding edge version. At work, you’ll probably be using the current LTS (Long Term Support) version. You might even have a side job client who hasn’t upgraded from v0.12 yet as well. NVM lets you run all of these versions on your computer. This helps you avoid errors encountered when using the wrong version of node.js, and prevents the tedious uninstall/re-install loop. For more info, check out the NVM documentation here.

Using the Node.js REPL Shell

Think of the REPL shell as a Command Line prompt for Node.js. I find it incredibly useful for tinkering around with features to see how they work. It’s faster and often easier than setting up a project or file-based scenario.

Understanding Callbacks in Node.js

PRO
They’ll make you laugh. They’ll make you cry.
They’ll make you want to jab sharp objects in your eye.
Until you understand them anyway, then they aren’t so bad. 
Take the time to learn them, because you will encounter them everywhere. This is a pro lesson, so consult this article from Nodejitsu and this one from The Node Way on error first callbacks if you aren’t an egghead.io subscriber.

Finding and Installing Packages with NPM

NPM is the Node Package Manager. Think of it as being similar to the App Store or Google Play for Node. Find, share and reuse packages from thousands of developers that allow you to iterate faster by building on top of the packages they’ve already built, or contribute your own packages as well. Since this lesson was recorded, npm has since been bundled into the node.js installer but the usage content is still relevant.

Yarn: A Javascript Package Manager

NPM was not without fault. Issues running at scale were uncovered, inefficiencies with workflow were identified. Some days, the kingdom was filled with sorrow. But, alas! Great shining knights from the land of F rode from far away, delivering yarn to the peasants, and the peasants rejoiced! Just kidding. Yarn is a substitute for NPM and aims to introduce better package management with improvements in speed, dependency management and security.

Introduction to Node.js Modules

PRO So far, you’ve installed Node, learned how to interact with it, and have installed packages. You have enough knowledge to dump all of the Javascript you can muster into a single page and launch your new app! But, before you do- allow me to introduce modules. Modules allow you to isolate your code into single task functions and consume them elsewhere in your application. This results in code reusability, easier testing, and easier to read code. The official Node.js docs cover the topic quite well and can be found here.

Using the Node.js HTTP Server

PRO You will encounter the Node.js HTTP server module over and over again. In this lesson, I introduce you to it and show you how to use it. Most of the time, you will will encounter its use through a framework where the details are abstracted away but I still think there is value in learning the core operation. You can get additional details from the Node.js docs here.

Memory and Garbage Collection

PRO This is one of my favorite lessons. You’ll probably not need this information until 2am on a Friday night when your app is blowing up and you need to analyze heap dumps to figure out why. Bookmark this lesson for that time, or watch it now and be ready when that incident happens (it will). Be sure to check out this RisingStack post on finding memory leaks as well. NOTE: The examples in this lesson need to be updated for version 6 and higher. Stay tuned for an updated lesson soon!

Using PM2 to Keep Your Apps Alive

So far, everything we’ve learned involves launching node via the command line. That’s not going to work on your production servers for multiple reasons:

  • No one should be logged in to your production servers
  • If the server restarts, someone has to manually start your node app
  • If the app crashes, it remains down until you restart it
  • No support for running multiple processes on multi-cpu machines

PM2 is one of several solutions to this problem. In this lesson, I introduce PM2 and show you how it works to address these issues.

Configuring PM2 for Node.js

PRO In this lesson, we dive a little deeper into using PM2 to configure scalable, resilient applications. While the details are specific to PM2, the concepts are valid for many of the other techniques for deploying Node.js applications. Concepts demonstrated here taken from the PM2 documentation found here.

Passing Environment Variables to Node.js

PRO Before long, you’ll find that a common way of getting environmental information to node is through the use of environment variables. (Yeah, that does seem redundant as I type it). Whether it’s database connection strings, API keys, or passwords- storing it as part of your code repo isn’t good practice so you need a strategy for getting that sensitive information to your app. This lesson shows how you can accomplish that with PM2. Concepts taken from the Node API docs here.

Automatically Restarting Node.js with PM2

When developing locally, it can often be frustrating to restart node each time you save a file to see the changes. PM2 has the ability to do this for you, and you’ll learn about it in this lesson. Nodemon is another popular tool with a similar feature set.

First API with Node.js, Express and MongoDB

This is a great lesson because so far, you’ve only been introduced to isolated concepts and examples. In this lesson, you get to see multiple things coming together to produce a product that you can actually see yourself using in the real world. You’ll learn to import data into mongodb, setup an express app as your API, and create a data model and connect to  mongodb using mongoose.

Using ES6 and Beyond with Node.js

Most ES6 features are now supported by the current version of Node. Before that was true, transpilers such as babel allowed us to use ES6 features, then transpiled the code to compatible syntax. This is a great lesson because not only does it demonstrate how to use the new features of ES6 in node.js, it also shows how to use npm scripts to setup build and start commands. These are great skills to have and really help shape the way you think about solving problems with runtime operations in Node.js.

Using the Realm Object Database in Node.js

I like the Realm database, and I like this lesson. It’s going to introduce you to using the Realm object database in Node.js, but it’s also going to expand on the concept of data persistence in Node.js as a whole. So far in this list, you’ve only seen MongoDB and it’s not the only choice you have. Choosing the storage engine for your application is a huge topic. We won’t discuss that here, but you will leave this lesson with a little more knowledge on the topic than you had previously. If you want to go deep on the subject, I’d recommend this post for an overview of NoSQL vs SQL and this post for an overview of the different NoSQL offerings.

Install Node.js Dashboard

The nodejs-dashboard is a tool from Formidable Labs that provides a really cool dashboard for running your node.js application locally. It has some great concepts like split panes for info vs. error logs, event loop delay, memory usage and cpu utilization. Definitely one to keep in your arsenal for troubleshooting pesky apps.

Use nodejs-dashboard Event Loop Delay

This lesson provides some great insight into “how to troubleshoot a nodejs app”. Instrumenting and troubleshooting your app should be thought of when you write the code, not when there is a problem. It’s too late then. This lesson hopefully gives you some insight into troubleshooting and some things to consider as you write new code.

Deploy Node.js on Docker

PRO It’s gotta feel like we’re making progress now, we’re deploying to Docker! w00t! w00t!
This lesson shows you how to do a basic deploy and covers the Best Practices Guide for deploying Node.js apps on Docker (it’s a real thing). See the next lesson in the list for additonal resources.

Build a Simple Node.js Server with Docker

Who loves Docker?
Everyone, that’s who. Even if you don’t know what it is, you love it. That’s why there are two Docker lessons on this list. (And because they are really great complimentary resources to each other). Docker can do a lot to help you automate and scale your deployments. Learning the basics here will give you the foundational knowledge you need start using Docker.

Deploy a Node.js Project with Zeit’s Now

Zeit’s Now is another tool in the deploy tool chain. Aimed at abstracting the server build/config/manage lifecycle away, it provides a tool to automate the deployment of your Node application. It’s pretty exciting to see, and a good lesson to watch as it provides additional information and context when evaluating your own deployment needs.

Deploy a Node.js Application on AWS with Elastic Beanstalk

PRO This lesson will show you how to package your application, setup a new environment and deploy into it using AWS Elastic Beanstalk. This lesson is great because in using Elastic Beanstalk, you’re able to see a complete end-to-end DevOps style solution. Everything is managed by configuration- there are no hand-crafted servers. No artisan-built masterpieces meticulously maintained by craftsmen. You get the idea. It’s completely possible to pull this level of automation off with other tools, I just like showing this one because it gives you an idea of what is possible. Check out the official AWS guides for this here.

Much deploy. Such choice.

So that was quite a bit of information to absorb around deploying your node app. You may be wondering why I showed so many different options. First, there is no right way™. Each has its pros and cons. You’re also likely to encounter all of these and more in your career, so I didn’t want to mislead you into thinking there is a right or wrong way. The right way is the one that works best with your team, your workflow, and your environment.

For me, I will struggle to sign off on deployment strategies that allow developers to push to production from their desktop. That comes from years of being the guy tied to the pager at 3am. Pushing from the desktop opens the door for changes to go to production without the right people knowing about it. It results in troubleshooting without relevant facts, and delays resolution. There are strategies to deal with this, but in the end: humans make mistakes, that is what we do best. I prefer automated systems that perform checks and balances and most important: don’t omit steps like logging actions taken and posting results to global communication channels so that everyone is aware of events as they happen. Having said that, I will agree that this generally isn’t an issue with smaller teams.

Creating JWT’s with Node.js

PRO I got really excited watching this lesson. JSON Web Tokens (JWT) are used to securely represent claims between two parties. The key word there is securely and hopefully security is part of every code discussion and release cycle in your organization. If it’s not, maybe it’s time to introduce it. No one wants to be the next Yahoo and open, frank communication is the key. In this lesson, you’ll learn what JWTs are made of, how to create them and how to debug them. For additional info on JWTs, see the official docs.

Getting Started with Express: MongoDB Integration

PRO In this first lesson in the series, Ben shows us how to use MongoDB as the backend datastore for our Express application. He shows how to use the native MongoDB client for Node.js and shows Mongoose, a popular ORM for Node.js/MongoDB.

Getting Started with Express: Creating Middleware

PRO As stated in this lesson, Express doesn’t actually do a lot. What makes it so powerful is the use of Middleware. You’ll learn exactly what that means in this lesson, the different types of middleware available, and see how middleware is implemented in the Express framework.

Getting Started with Express: Using Streams

PRO You’ll encounter streams everywhere in Node.js, and sometimes not even know it. Streams are instances of Event Emitter and two examples are the http server requests and process.stdout. In this lesson, you will be introduced to Streams and see how they are used in the Express framework. Even though it’s unlikely you will access streams directly (unless creating your own stream), it’s still important to understand how they work as you will be a consumer of them. For more info, see the official Node.js docs.

Getting Started with Express: Routing Code Organization

As your application grows, so do the number of routes and the need for code organization grows exponentially. In this lesson, you will learn some tips and strategies for organizing your routing code.

Getting Started with Express: Advanced Routing

This lesson goes beyond basic routing. In it, you will learn about error handling, downloads and parsing data in requests and responses. It’s a great way to see some examples of what is possible for building business logic into your application.

Getting Started with Express: HTTP Verbs

PRO You’ll probably reach the limits of what type of app you can build if you only use HTTP GET requests, so in this lesson you will learn to handle all of the standard HTTP verbs and use them to modify the data in your application.

Getting Started with Express: Static Files

PRO It’s not always clever, catchy code. Sometimes you just need to serve up a simple static file. You’ll learn exactly how to do that in this lesson using the Express static file handler. Official docs found here.

Getting Started with Express: Template Engines

PRO Express supports multiple template engines such as Handlebars and Jade to serve up the UI for your application. In this lesson, learn how to use them in your app. Official docs are here.

Where Do I Go From Here?

Jumpstart to Node.js

This is just the tip of the iceberg. There is so much more to learn about Node.js, but save that for another day. For now, find a project to use Node.js with. Get as far as you can. When you hit a wall, go find that specific answer. When your brain faces a specific problem you need to solve, when you find the answer you will retain it better.

Pick a topic/project that you are already familiar with. If you don’t know anything about the effects of thermal exhaust port size on large scale weapons facilities, that’s probably a poor project choice. You’re likely to struggle to learn to many concepts at once, learn less, and make mistakes.

If you are feeling comfortable with Node.js at this point, it may be time to take your skills to the next level with a production application. Talk to your boss or supervisor. Your boss and your IT team will be leery of introducing a new technology. Every new technology comes with a cost of support and engineering resources. Think about what the simplest point of entry into your environment might be and be prepared to show some quick wins as well as the ability to fail fast if the project doesn’t go well. Remember too, that failure to complete a project does not mean failure, it was a learning experience that the entire team can use as a tool. The faster you learn whatever result may be, the faster your team will ultimately succeed.

Always feel free to hit me up, too! You can reach me on Twitter.