Skip to content

renatoxm/vod-video-on-demand-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VOD - Video On Demand API In Node.js + Express.js + Typescript

NodeJS Express.js TypeScript Docker MongoDB Vercel AWS

API for a Video on demand service using:

  • Node.js
  • Express.js
  • TypeScript
  • Docker
  • MongoDB & Atlas Database
  • Vercel
  • AWS S3

Project was developed over my node.js boilerplate, available here.

If you are looking for high-volume streaming, you should read my article

The ideal VOD Platform build for high-volume Streaming Data

Features

  1. Register user
  2. Login
  3. Get current logged in user (me)
  4. Upload video
  5. Get all videos
  6. Stream a video

Technologies

Installation

cp .env.example .env

npm i

Creating a AWS S3 Bucket

  1. Create a new IAM User:

    1. Choose programatic access.
    2. Select "Attach existing policies directly"
    3. Add AmazonS3FullAccess.
  2. Save the access key and secret key for the IAM User.

    1. This is used for programmatic access in the API Route.
  3. Install the AWS CLI:

    1. Run aws configure.
    2. Enter your root AWS user access key and secret key.
    3. Enter your default region.
  4. Create an .env.local file similar to .env.example.

    1. Enter your access key and secret key from the IAM user.
  5. You must configure cors, for the upload to work

    1. S3 Documentation
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": ["s3:DeleteObject", "s3:GetObject", "s3:ListBucket", "s3:PutObject", "s3:PutObjectAcl"],
          "Resource": ["arn:aws:s3:::BUCKET_NAME", "arn:aws:s3:::BUCKET_NAME/*"]
        }
      ]
    }
  6. Run cdk bootstrap.

  7. Run cdk deploy to create an S3 bucket with an IAM policy.

  8. Visit your newly created S3 bucket and retrieve the name and region.

  9. Add the name and region to .env.local.

  10. Run npm run dev to start the app at localhost:3000.

  11. Choose a .png or .jpg file.

  12. You should see your file successfully uploaded to S3.

This example uses createPresignedPost instead of getSignedUrlPromise to allow setting max/min file sizes with content-length-range.

Scripts

Basic

In order to compile and run our ts code we're going to use three scripts, start, dev and build.

start is the one that will be executed by the server in case of a deployment:

npm start

dev for our normal development

npm run dev

and build to compile our TypeScript code

npm run build

Linter and Prettier actions

run lint for linter

npm run lint

or prettier:check to find errors

npm run prettier:check

or use write to fix problems

npm run prettier:write

Testing

For testing use

npm run test

Docker option (run client locally and server on container)

To start Docker server run docker up -d command. On the first time docker will install the containers.

  1. Start client locally with npm i
cd client

npm run prod
  1. Run server on Docker container
cd server

docker-compose up -d

To stop docker use ctrl + c keyboard command

License

This project is licensed under the MIT license. For more information, see the LICENSE file.

All images used in this repository are from Pexels and are under their LICENSE.

Thank you notes

Thanks to Pexels and their community for sharing such wonderful videos and images for free.