This is an example project to demonstrate how to make a serverless application with Node.js
, TypeScript
, and Claudia.js
on Amazon Web Services (AWS)
.
Run npm i
to install dependencies.
Run npm run glob
to install typescript
, ts-node
, nodemon
, and claudia
. Those are all required for this project.
env.json
is used for setting environment variables (.gitignore ignores this file to protect you from leaking top secrets).
By default, the project uses conn variable to link MongoDB
.
{
"conn": "mongodb://{username}:{password}@ds123456.mlab.com:45678/{dbname}"
}
You can use mLib
for testing.
Development server
loads env.json
in serve.ts
when you run npm run dev
, and Claudia.js
also uses env.json
to set environment variables on Lambda
.
Run npm run dev
for a dev server. It uses nodemon
to watch files and uses ts-node
to run .ts code.
Your IAM user
must to have permissions at least Lambda
, API Gateway
, and IAM
in order to run Claudia.js
.
Add the keys to your .aws/credentials
file.
[claudia]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_ACCESS_SECRET
The AWS credentials file – located at ~/.aws/credentials on Linux, macOS, or Unix, or at C:\Users\USERNAME .aws\credentials on Windows. This file can contain multiple named profiles in addition to a default profile.
See more detail in INSTALLING AND CONFIGURING CLAUDIA.JS.
-
Run
npm run build
to compile .ts to .js intodist folder
. It will also copy package.json intodist folder
in order to runClaudia.js
.If you are using Windows OS, please run
npm run build-win
instead. -
Run
npm run create
to initializeClaudia.js
.Claudia.js
will install packages, zip files, upload toLambda
, and setupAPI Gateway
.⚠️ The--region
option is mandatory for the create command, and thepackage.json
usesus-east-1
for the default. If you want to deploy to the different region, please change it before you run the script.Here are the AWS Available Regions.
See more detail in Claudia.js create command.
-
Run
npm run update
to update api if you have donenpm run create
before. Be careful to keep claudia.json intodist folder
. Claudia will generate it after creating api, and use it to update api.See more detail in Claudia.js update command.
This project uses mocha
, sinon
, and chai
for unit testing.
All files with *.spec.ts will be tested.
Run npm run test
to execute all unit tests, and you can see the html report on /mochawesome-report/mochawesome.html
.
Run npm run coverage
to execute coverage check, and you can see the html report on /coverage/index.html
.
see API.md
for API Usages