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
- Register user
- Login
- Get current logged in user (me)
- Upload video
- Get all videos
- Stream a video
cp .env.example .env
npm i
-
Create a new IAM User:
- Choose programatic access.
- Select "Attach existing policies directly"
- Add
AmazonS3FullAccess
.
-
Save the access key and secret key for the IAM User.
- This is used for programmatic access in the API Route.
-
Install the AWS CLI:
- Run
aws configure
. - Enter your root AWS user access key and secret key.
- Enter your default region.
- Run
-
Create an
.env.local
file similar to.env.example
.- Enter your access key and secret key from the IAM user.
-
You must configure cors, for the upload to work
{ "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/*"] } ] }
-
Run
cdk bootstrap
. -
Run
cdk deploy
to create an S3 bucket with an IAM policy. -
Visit your newly created S3 bucket and retrieve the name and region.
-
Add the name and region to
.env.local
. -
Run
npm run dev
to start the app atlocalhost:3000
. -
Choose a
.png
or.jpg
file. -
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
.
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
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
For testing use
npm run test
To start Docker server run docker up -d command. On the first time docker will install the containers.
- Start client locally with npm i
cd client
npm run prod
- Run server on Docker container
cd server
docker-compose up -d
To stop docker use ctrl + c keyboard command
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.
Thanks to Pexels and their community for sharing such wonderful videos and images for free.