Ep.03: Tools & Setup for building and testing a Node Web App

Ep.03: Tools & Setup for building and testing a Node Web App

This article is part of an in-depth comparison series of the top Node frameworks. We'll cover all the important aspects: market share, learning curve, ecosystem, security and more. To compare them properly, we will build the exact same app in all these frameworks (plus Vanilla Node), observe all the steps along the way and then benchmark them as we progressively add more functionalities.

Table of contents

  1. Market Share Distribution Analysis: Picking the most used frameworks
  2. Planning Phase: Use cases, Minimum Viable Product requirements, Architecture
  3. Tools & Setup: Getting started and setting up the tools and environment
  4. Scaffolding: Project Settings and Configuration, Common template repo
  5. Express: basic app (MVP)
  6. Koa: basic app (MVP)
  7. Express Flavors: basic app (MVP) in multiple variants: OOP, FP, TypeScript, single-file etc
  8. Nest.js: basic app (MVP)
  9. Fastify: basic app (MVP)
  10. Next.js: basic app (MVP)
  11. Vanilla Node: basic app (MVP)
  12. Functional testing with Postman + Newman


Sleeves up and let's start building! Oh, wait, am I being one of those jerks that just assume you have the exact same environment as me and ...?

Yeah, let's roll back a little, and make sure we're on the same page. Or, at least, on the same setup, right?

If you're a seasoned developer, just use your preferred package manager for your OS, a source manager, a database manager, an IDE, an API development and testing tool, some containerization platform and, obviously, Node.js - complete with TypeScript and some basics like ESLint, Prettier, ts-node, etc.


If you're new-ish to development, let's look at these in more detail and take our pick.

There's an entire grocery list of tools you'll need if you want to hop along and try building an app with any Node.js framework. Well, you technically don't need them... You could, for example, skip the database manager and use the terminal to scour through your databases. If you choose to do so, let me know, I have a good friend who's a shrink specialized in the Angry Developer Syndrome, and he'll give you a discount. Anywho, let's open a terminal and let's get...:

  • Some package manager to make setting up easier and not install everything manually. If you're on a Mac: Homebrew or equivalent; If you're on Windows, you already have Winget preinstalled (some prefer Chocolatey though), and on Linux you'd have apt-get by default. The package manager will help you easily setup everything below. Please note that this is not the same thing as NPM (Node Package Manager).
  • A source manager like Git or Mercurial. If you did not skip the previous step, you can simply type in your terminal the relevant line from below:

# on Windows
winget install -e --id Git.Git

# on a Mac
brew install git

# on Linux
sudo apt-get install -y git        

  • This is a Node project, so, surprise-surprise, you'll need to install Node (which includes the NPM mentioned above). Again, with a package manager, it's just one simple command:

# on Windows
winget install -e --id OpenJS.NodeJS

# on a Mac
brew install node

# on Linux
sudo apt-get install -y node        

See the pattern? Simple, right?

  • Next, you'll need some sort of Integrated Development Environment (IDE), which is just a fancy word for "code editor and stuff...". Most people nowadays go with the free Visual Studio Code (VSCode) from Microsoft, but when something from Big Corporate comes for free, usually it means you're not the customer, you're the product, and you're paying in a different way. So, I'll prefer VSCodium (which is an open-source fork of VSCode). It's virtually identical, except for the part where it sends my daily activity report to our friends at Microsoft. We're gonna install some standard extensions like Docker, ESLint and Prettier along with it and we're gonna set the $PATH, so this is slightly more complicated:

# on Windows
winget install -e --id VSCodium.VSCodium
codium --install-extension dbaeumer.vscode-eslint
codium --install-extension ms-azuretools.vscode-docker
codium --install-extension esbenp.prettier-vscode
$VSCodiumPath = "C:\Program Files\VSCodium\bin"
$env:Path += ";$VSCodiumPath"
[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::User)


# on a Mac
brew install --cask vscodium
extensions=(
  dbaeumer.vscode-eslint
  esbenp.prettier-vscode
  ms-azuretools.vscode-docker
)
for extension in "${extensions[@]}"; do
  codium --install-extension "$extension"
done
echo 'export PATH="/Applications/VSCodium.app/Contents/Resources/app/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc


# on Linux
sudo apt-get install -y codium
extensions=(
  dbaeumer.vscode-eslint
  esbenp.prettier-vscode
  ms-azuretools.vscode-docker
)
for extension in "${extensions[@]}"; do
  codium --install-extension "$extension"
done
echo 'export PATH="$PATH:/usr/share/codium/bin"' >> ~/.bashrc
source ~/.bashrc        

  • Since we mentioned Docker, the world's beloved containerization platform, we're also gonna install this:

# on Windows - you need to enable WSL2
winget install -e --id Docker.DockerDesktop
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
wsl --set-default-version 2


# on a Mac
brew install docker


# on Linux - you need to install Docker Compose separately
sudo apt-get install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $(whoami)
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose        

  • We're going to use databases, so we'll need a database manager. There are many, but few are free and allow you to interact with almost any type of database, so, without further ado, let's install dBeaver:

# on Windows
winget install -e --id DBeaver.DBeaver


# on a Mac
brew install --cask dbeaver-community


# on Linux
wget -O - https://dbeaver.io/debs/dbeaver.gpg.key | sudo apt-key add -
echo "deb https://dbeaver.io/debs/dbeaver-ce /" | sudo tee /etc/apt/sources.list.d/dbeaver.list
sudo apt-get update
sudo apt-get install -y dbeaver-ce        

  • Optional, but let's get Postman as well, it's a widely used tool, and also Newman, to run collections locally:

# on Windows
winget install -e --id Postman.Postman
npm install --global newman

# on a Mac
brew install --cask postman
npm install --global newman

# on Linux
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
sudo tar -xzf postman.tar.gz -C /opt
sudo ln -s /opt/Postman/Postman /usr/local/bin/postman
npm install --global newman        

  • We will need TypeScript. We will also want some basic utilities for linting (automatically formatting the code and making sure it adheres to some basic standards) and containerization (making sure our app runs the same on any environment), so we might just as well do this in one go. This is the same on any operating system:

npm install --global npx eslint prettier typescript ts-node        

If you want a script that installs everything in one go, check this small repo, it has a PowerShell and a BatchScript version that does all the heavy lifting for you if you're on windows: microservice-quickstart

Check if everything is installed correctly with this small script if you're on Mac/Linux:

#!/bin/bash

check_version() {
    if ! command -v $1 &> /dev/null
    then
        echo "$1 not installed"
    else
        echo "$1 version: $($1 --version)"
    fi
}

check_version git
check_version node
check_version codium
check_version docker
check_version dbeaver
check_version postman
check_version npm
check_version tsc        

Caveat, I don't own a Linux machine, also installation may vary by distribution, so you need to navigate that on your own.

If you're on Windows, this equivalent PowerShell script should confirm that everything is correctly installed:

function Check-Version {
    param (
        [string]$command
    )
    $path = Get-Command $command -ErrorAction SilentlyContinue
    if ($path) {
        try {
            & $command --version
        } catch {
            Write-Host "$command version information not available"
        }
    } else {
        Write-Host "$command not installed"
    }
}

Check-Version "git"
Check-Version "node"
Check-Version "codium"
Check-Version "docker"
Check-Version "dbeaver"
Check-Version "postman"
Check-Version "npm"
Check-Version "tsc"         

If something yells at you through the screen, let me know in the comments and we can yell right back and bring them in line, no worries. Otherwise, we're good to go.

要查看或添加评论,请登录

Teolin Codreanu的更多文章

社区洞察

其他会员也浏览了