A complete setup guide to run the Movie Collection API locally using Node.js, Express, MongoDB (Atlas), TypeScript, and Bun as the package manager.
Ensure the following tools are installed based on your operating system:
- Node.js (or install via
nvm
) - Bun (recommended)
- Git
- MongoDB Atlas (or local MongoDB if preferred)
.env
file with yourTMDB_API_KEY
, Mongo URI, etc.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
Replace
v0.40.3
with the latest release version.
powershell -c "irm https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | iex"
Replace
v0.40.3
with the latest release version.
If script execution is restricted, run:
Set-ExecutionPolicy RemoteSigned -Scope Process
curl -fsSL https://bun.sh/install | bash
powershell -c "irm https://bun.sh/install.ps1 | iex"
If script execution is restricted, run:
Set-ExecutionPolicy RemoteSigned -Scope Process
To install a specific version of Bun on Linux/Mac, checkout the Bun Docs.
Install Chocolatey to manage packages:
Open PowerShell as Administrator and run:
Set-ExecutionPolicy Bypass -Scope Process -Force; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Then install essential tools:
choco install git nodejs mongodb.install bun vscode mongodb-atlas postman arc-browser warp mongodb-atlas -y # optionally install node if nvm is already installed
Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install required tools:
brew install git node [email protected] mongodb/brew/mongosh mongodb-atlas-cli # optionally install node if nvm is already installed
brew install --cask visual-studio-code postman arc warp
sudo apt update
sudo apt install -y curl git gnupg
# Install Node.js using NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts
# Install Bun
curl -fsSL https://bun.sh/install | bash
# Optional: VS Code and MongoDB CLI
sudo snap install code --classic
sudo pacman -Syu git curl base-devel
# Node.js (or use NVM)
sudo pacman -S nodejs npm
# Bun
curl -fsSL https://bun.sh/install | bash
# VS Code
sudo pacman -S code
Note: Use your package manager or Snap/Flatpak for other tools like Postman, Warp, Arc.
cd ~/Documents
git clone https://github.com/techstackspace/express-projects.git
cd express-projects
git checkout feature/01-movie-collection-api
bun install
Delete
package-lock.json
if switching tobun
.
npm install
To use the TMDB API, follow these steps:
-
Create or Access Your TMDB Account
- If you don't have an account: Sign up here
- If you already have an account: Log in here
-
Generate Your API Key
- Go to the API settings page
- Choose the "Developer" plan by filling out the developer subscription form
- Accept the terms for personal use
-
Access Your API Key
- After approval, visit the API key details page
- Copy your API key
-
Add the API Key to Your Project
-
Open your
.env
file -
Add the following line:
TMDB_API_KEY=<your_tmdb_api_key>
-
β Make sure to restart your development server after updating the
.env
file.
Create a .env
file in the root directory and add:
MONGO_URI=<mongo_uri>
TMDB_API_KEY=<your_tmdb_api_key>
PORT=5000
Replace <mongo_uri>
with one of the following options:
- Local MongoDB:
mongodb://localhost:27017/movies-db
- MongoDB Atlas: Use the connection string from your Atlas cluster, e.g.,
mongodb+srv://<username>:<password>@<cluster>.mongodb.net/movies-db?retryWrites=true&w=majority
Pro Tip: You can also import the
movies-db.movies.json
file into MongoDB Compass or Atlas to quickly populate your database for testing.
bun dev
bun run build
bun start
Ensure MongoDB Atlas (or Compass) is running and accessible.
To fetch and seed top-rated movies from TMDB:
bun run seed
mongosh # optional
This script is located at:
src/scripts/seedMovies.ts
- Optional query params:
search
,genre
,country
,limit
,page
- Fetch top 10 movies sorted by rating
- Get movie by ID
- Add a new movie to the database
.
βββ src/
β βββ models/
β β βββ Movie.ts
β βββ routes/
β β βββ movies.ts
β βββ scripts/
β β βββ seedMovies.ts
β βββ index.ts
βββ .env
βββ tsconfig.json
βββ bun.lockb / package-lock.json
βββ README.md
brew "gh"
brew "git"
brew "[email protected]"
brew "mongodb-atlas-cli"
brew "oven-sh/bun/bun"
brew "mongodb/brew/mongosh"
cask "amazon-q"
cask "postman"
cask "arc"
cask "visual-studio-code"
cask "warp"
cask "mongodb-compass"
vscode "amazonwebservices.codewhisperer-for-command-line-companion"
vscode "mongodb.mongodb-vscode"
vscode "bengreenier.vscode-node-readme"
vscode "yzhang.markdown-all-in-one"
vscode "Postman.postman-for-vscode"
vscode "esbenp.prettier-vscode"
vscode "GitHub.github-vscode-theme"
vscode "PKief.material-icon-theme"
Use this to install all tools in the project directory:
brew bundle --file=config/macOS/Brewfile
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="git" />
<package id="gh" />
<package id="bun" />
<package id="nvm" />
<package id="mongodb.install" />
<package id="mongodb-compass" />
<package id="mongodb-atlas" />
<package id="postman" />
<package id="vscode" />
<package id="warp" />
</packages>
Use this to install all tools in the project directory:
choco install config\choco-packages.config -y
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Check if the OS is Linux
if [[ "$OSTYPE" != "linux-gnu"* ]]; then
echo "This script is intended for Linux systems."
exit 1
fi
# Source the os-release file to get distribution information
if [ -r /etc/os-release ]; then
. /etc/os-release
DISTRO_ID=$ID
DISTRO_VERSION_ID=$VERSION_ID
else
echo "Cannot determine Linux distribution."
exit 1
fi
# Determine the package manager and install MongoDB accordingly
case "$DISTRO_ID" in
ubuntu|debian)
# Install required packages
sudo apt-get update
sudo apt-get install -y gnupg curl
...
Use this to install all tools in the project directory:
chmod +x config/linux/install.sh
To run it with sudo, run:
sudo config/linux/install.sh
code --install-extension amazonwebservices.aws-toolkit-vscode
code --install-extension mongodb.mongodb-vscode
code --install-extension bengreenier.vscode-node-readme
code --install-extension yzhang.markdown-all-in-one
code --install-extension postman.postman-for-vscode
code --install-extension esbenp.prettier-vscode
code --install-extension github.github-vscode-theme
code --install-extension pkief.material-icon-theme
If, after development, you need to reinstall specific packages or all packages, run:
To uninstall tools:
brew uninstall git node [email protected] bun mongodb-atlas-cli mongosh gh
brew uninstall --cask visual-studio-code postman arc warp mongodb-compass amazon-q
To remove Homebrew itself:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
To uninstall packages:
choco uninstall git nodejs mongodb.install mongodb-compass amazon-q postman arc-browser vscode warp-terminal -y
To uninstall Chocolatey (run in Administrator PowerShell):
Remove-Item -Recurse -Force "$env:ProgramData\chocolatey"
[Environment]::SetEnvironmentVariable('Path', ($env:Path -replace ';C:\\ProgramData\\chocolatey\\bin',''), 'Machine')
For APT (Ubuntu/Debian):
sudo apt remove --purge nodejs git mongodb-org -y
sudo snap remove code
sudo rm -rf ~/.bun ~/.nvm ~/.npm ~/.config/bun
For Pacman (Arch/Manjaro):
sudo pacman -Rns nodejs npm git code mongodb --noconfirm
rm -rf ~/.bun ~/.nvm ~/.npm ~/.config/bun
Your feedback is incredibly valuable and helps improve these resources for the entire community.
Whether you've followed a tutorial, read the documentation, watched a video, or used a scriptβI'd love to hear your thoughts!
- What worked well for you?
- What was unclear or confusing?
- Suggestions for improvement or new topics?
- Bugs or outdated instructions?
Your input helps shape better content for developers like you. Thank you!