Node.js: Tools & Skills
By James Hibbard, Michael Wanyoike, Nilson Jacques and
()
About this ebook
While there have been quite a few attempts to get JavaScript working as a server-side language, Node.js (frequently just called Node) has been the first environment that's gained any traction. It's now used by companies such as Netflix, Uber and Paypal to power their web apps. Node allows for blazingly fast performance; thanks to its event loop model, common tasks like network connection and database I/O can be executed very quickly indeed.
In this book, we'll take a look at a selection of the related tools and skills that will make you a much more productive Node developer. It contains:
- Installing Multiple Versions of Node.js Using nvm
- A Beginner's Guide to npm
- Create New Express.js Apps in Minutes with Express Generator
- An Introduction to AdonisJs, a Laravel-like Node.js Framework
- Top 5 Developer-friendly Node.js API Frameworks
- Using MySQL with Node.js and the mysql JavaScript Client
- Introduction to MongoDB
James Hibbard
I'm a web developer currently living in the sunny north of Germany. I enjoy coding in both JavaScript and Ruby and can often be found in SitePoint's JavaScript forum. When I'm not coding, I enjoy running.
Read more from James Hibbard
Vue.js: 11 Practical Projects Rating: 0 out of 5 stars0 ratingsLearn Vue.js: The Collection Rating: 0 out of 5 stars0 ratingsYour First Week With Node.js Rating: 0 out of 5 stars0 ratingsVue.js: Tools & Skills Rating: 0 out of 5 stars0 ratings
Related to Node.js
Related ebooks
Jump Start PHP Environment: Master the World's Most Popular Language Rating: 0 out of 5 stars0 ratingsNode.js: Novice to Ninja Rating: 0 out of 5 stars0 ratingsJump Start Vue.js Rating: 4 out of 5 stars4/5Jump Start Git Rating: 0 out of 5 stars0 ratings50 Recipes for Programming Node.js Rating: 3 out of 5 stars3/5Beginning Mobile Application Development in the Cloud Rating: 0 out of 5 stars0 ratingsGetting Started with Docker Rating: 0 out of 5 stars0 ratingsNode.js, JavaScript, API: Interview Questions and Answers Rating: 5 out of 5 stars5/5Visual Studio Code: End-to-End Editing and Debugging Tools for Web Developers Rating: 0 out of 5 stars0 ratingsLearn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/5Hands-on React Native Rating: 1 out of 5 stars1/5CSS Master Rating: 0 out of 5 stars0 ratingsModern Web Development with Go: Build real-world, fast, efficient and scalable web server apps using Go programming language Rating: 0 out of 5 stars0 ratingsASP.NET Application Development Fundamentals Rating: 0 out of 5 stars0 ratingsRuby Developers Guide Rating: 3 out of 5 stars3/5Jump Start Sass: Get Up to Speed With Sass in a Weekend Rating: 0 out of 5 stars0 ratingsJavaScript: Best Practice Rating: 0 out of 5 stars0 ratingsJump Start MySQL: Master the Database That Powers the Web Rating: 0 out of 5 stars0 ratingsJavaScript: Novice to Ninja Rating: 2 out of 5 stars2/5Advanced Penetration Testing with Kali Linux: Unlocking industry-oriented VAPT tactics (English Edition) Rating: 0 out of 5 stars0 ratingsDecoding JavaScript: A Simple Guide for the Not-so-Simple JavaScript Concepts, Libraries, Tools, and Frameworks (English Edition) Rating: 0 out of 5 stars0 ratingsPython for Cybersecurity Cookbook: 80+ practical recipes for detecting, defending, and responding to Cyber threats (English Edition) Rating: 0 out of 5 stars0 ratingsExploring Web Components: Build Reusable UI Web Components with Standard Technologies (English Edition) Rating: 0 out of 5 stars0 ratingsHTML5 and CSS3 All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsCSS3 Foundations Rating: 4 out of 5 stars4/5JavaScript: Best Practices to Programming Code with JavaScript: JavaScript Computer Programming, #3 Rating: 0 out of 5 stars0 ratings
Programming For You
HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Python Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratingsLearn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratingsJava for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5The Unofficial Guide to Open Broadcaster Software: OBS: The World's Most Popular Free Live-Streaming Application Rating: 0 out of 5 stars0 ratingsPYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Hacking: Ultimate Beginner's Guide for Computer Hacking in 2018 and Beyond: Hacking in 2018, #1 Rating: 4 out of 5 stars4/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5The Little SAS Book: A Primer, Sixth Edition Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Teach Yourself C++ Rating: 4 out of 5 stars4/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5
Reviews for Node.js
0 ratings0 reviews
Book preview
Node.js - James Hibbard
Preface
While there have been quite a few attempts to get JavaScript working as a server-side language, Node.js (frequently just called Node) has been the first environment that's gained any traction. It's now used by companies such as Netflix, Uber and Paypal to power their web apps. Node allows for blazingly fast performance; thanks to its event loop model, common tasks like network connection and database I/O can be executed very quickly indeed.
In this book, we'll take a look at a selection of the related tools and skills that will make you a much more productive Node developer.
Who Should Read This Book?
This book is for anyone who wants to start learning server-side development with Node.js. Familiarity with JavaScript is assumed, but we don't assume any previous back-end development experience.
Conventions Used
Code Samples
Code in this book is displayed using a fixed-width font, like so:
A Perfect Summer's Day
It was a lovely day for a walk in the park.
The birds were singing and the kids were all back at school.
Where existing code is required for context, rather than repeat all of it, ⋮ will be displayed:
function animate() {
⋮
new_variable = Hello
;
}
Some lines of code should be entered on one line, but we’ve had to wrap them because of page constraints. An ➥ indicates a line break that exists for formatting purposes only, and should be ignored:
URL.open("http://www.sitepoint.com/responsive-web-
➥design-real-user-testing/?responsive1");
You’ll notice that we’ve used certain layout styles throughout this book to signify different types of information. Look out for the following items.
Tips, Notes, and Warnings
Hey, You!
Tips provide helpful little pointers.
Ahem, Excuse Me ...
Notes are useful asides that are related—but not critical—to the topic at hand. Think of them as extra tidbits of information.
Make Sure You Always ...
... pay attention to these important points.
Watch Out!
Warnings highlight any gotchas that are likely to trip you up along the way.
Supplementary Materials
https://www.sitepoint.com/community/ are SitePoint’s forums, for help on any tricky problems.
books@sitepoint.com is our email address, should you need to contact us to report a problem, or for any other reason.
Chapter 1: Installing Multiple Versions of Node.js Using nvm
by Michael Wanyoike and James Hibbard
When working with Node.js, you might encounter situations where you need to install multiple versions of the runtime.
For example, maybe you have the latest version of Node set up on your machine, yet the project you’re about to start working on requires an older version. Or maybe you’re upgrading an old Node project to a more modern version and it would be handy to be able to switch between the two while you make the transition.
Without a good tool, this would mean spending a lot of time and effort manually uninstalling and reinstalling Node versions and their global packages. Fortunately, there’s a better way!
Introducing nvm
nvm stands for Node Version Manager. As the name suggests, it helps you manage and switch between different Node versions with ease. It provides a command-line interface where you can install different versions with a single command, set a default, switch between them and much more.
OS Support
nvm supports both Linux and macOS, but that’s not to say that Windows users have to miss out. There’s a second project named nvm-windows that offers Windows users the option of easily managing Node environments. Despite the name, nvm-windows is not a clone of nvm, nor is it affiliated with it. However, the basic commands listed below (for installing, listing and switching between versions) should work for both nvm and nvm-windows.
Installation
Let’s first cover installation for Windows, macOS and Linux.
Windows
First, we need to do a little preparation:
uninstall any existing versions of Node.js
delete any existing Node.js installation directories (such as C:\Program Files\nodejs)
delete the existing npm install location (such as C:\Users\
After this, download and run the latest stable installer and you should be good to go!
macOS/Linux
Unlike Windows, removing previous Node and npm installations in macOS and Linux is optional. If this is something you want to do, there are plenty of good resources available online. For example, here’s how to remove Node on macOS and on Linux. And here’s how you can remove any previous npm installation you might have.
You can install nvm using cURL or Wget. On your terminal, run the following:
With cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
Or with Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
Note that the version number (v0.35.2) will change as the project develops, so it’s worth checking the relevant section of project’s home page to find the most recent version.
This will clone the nvm repository to ~/.nvm and will make the required changes to your bash profile, so that nvm is available from anywhere in your terminal.
And that’s it! Reload (or restart) your terminal and nvm is ready to be used.
Using nvm
If installed correctly, the nvm command is available anywhere in you terminal. Let’s see how to use it to manage Node.js versions.
Install Multiple Versions of Node.js
One of the most important parts of nvm is, of course, installing different versions of Node.js. For this, nvm provides the nvm install command. You can install specific versions by running this command followed by the version you want. For example:
nvm install 12.14.1
By running the above in a terminal, nvm will install Node.js version 12.14.1.
Running nvm use
nvm-windows users will have to run nvm use 12.14.1 after installing.
nvm follows SemVer, so if you want to install, for example, the latest 12.14 patch, you can do it by running:
nvm install 12.14
nvm will then install Node.js version 12.14.X, where X is the highest available version. At the time of writing, this is 1, so you’ll have the 12.14.1 version installed on your system.
You can see the full list of available