Skip to content

A curated collection of standalone Express.js API applications, each housed in its own branch. These projects serve as modular examples or starting points for building RESTful APIs using Express.js. Many branches incorporate Mongoose for MongoDB integration, showcasing various patterns and best practices

Notifications You must be signed in to change notification settings

techstackspace/express-projects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Movie Collection API Setup

YouTube

A complete setup guide to run the Movie Collection API locally using Node.js, Express, MongoDB (Atlas), TypeScript, and Bun as the package manager.


1. Prerequisites

Ensure the following tools are installed based on your operating system:

Required for All Platforms

  • Node.js (or install via nvm)
  • Bun (recommended)
  • Git
  • MongoDB Atlas (or local MongoDB if preferred)
  • .env file with your TMDB_API_KEY, Mongo URI, etc.

Install NVM (Optional β€” if you prefer managing Node versions via nvm)

macOS and Linux

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

Replace v0.40.3 with the latest release version.

Windows

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

Install Bun (Optional β€” if you prefer bun over node)

macOS and Linux

curl -fsSL https://bun.sh/install | bash

Windows

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.


Windows

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

macOS (via Homebrew)

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

Linux (APT or Pacman)

For Ubuntu/Debian:

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

For Arch/Manjaro (Pacman):

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.


2. Clone the Project

cd ~/Documents
git clone https://github.com/techstackspace/express-projects.git
cd express-projects
git checkout feature/01-movie-collection-api

3. Install Dependencies

Using Bun (preferred):

bun install

Delete package-lock.json if switching to bun.

Or using npm:

npm install

4. How to Get Your TMDB API Key

To use the TMDB API, follow these steps:

  1. Create or Access Your TMDB Account

  2. Generate Your API Key

  3. Access Your API Key

  4. 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.

5. Environment Variables**

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.


6. Start the Server

Development:

bun dev

Build and Run:

bun run build
bun start

Ensure MongoDB Atlas (or Compass) is running and accessible.


7. Seed Database with Top Movies

To fetch and seed top-rated movies from TMDB:

bun run seed
mongosh # optional

This script is located at: src/scripts/seedMovies.ts


8. API Endpoints

πŸ” GET /api/movies

  • Optional query params: search, genre, country, limit, page

🌟 GET /api/movies/top

  • Fetch top 10 movies sorted by rating

πŸ” GET /api/movies/:id

  • Get movie by ID

βž• POST /api/movies

  • Add a new movie to the database

9. Project Structure

.
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── Movie.ts
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── movies.ts
β”‚   β”œβ”€β”€ scripts/
β”‚   β”‚   └── seedMovies.ts
β”‚   β”œβ”€β”€ index.ts
β”œβ”€β”€ .env
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ bun.lockb / package-lock.json
β”œβ”€β”€ README.md

10. Recommended Tools via Brewfile

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

11. Recommended Tools via Chocolatey

<?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

12. Recommended Tools via APT, Pacman, etc

#!/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

13. Installation of VSCode Extensions

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

14. Uninstalling Tools

If, after development, you need to reinstall specific packages or all packages, run:

macOS (Homebrew)

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)"

Windows (Chocolatey)

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')

Linux

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

15. Resources


16. Feedback & Suggestions

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 you can share:

  • What worked well for you?
  • What was unclear or confusing?
  • Suggestions for improvement or new topics?
  • Bugs or outdated instructions?

Submit your feedback here:

Submit Feedback Form

Your input helps shape better content for developers like you. Thank you!


17. Social Media

  • Instagram
  • Threads
  • Facebook
  • TikTok
  • YouTube
  • X

About

A curated collection of standalone Express.js API applications, each housed in its own branch. These projects serve as modular examples or starting points for building RESTful APIs using Express.js. Many branches incorporate Mongoose for MongoDB integration, showcasing various patterns and best practices

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published