Skip to content

An easy way to make a serverless application with Node.js, TypeScript, and Claudia.js on Amazon Web Services (AWS).

Notifications You must be signed in to change notification settings

gong-hao/ts-node-claudia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ts-node-claudia

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

Install dependencies

Run npm i to install dependencies.

Install global packages

Run npm run glob to install typescript, ts-node, nodemon, and claudia. Those are all required for this project.

Environment variables

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.

Development server

Run npm run dev for a dev server. It uses nodemon to watch files and uses ts-node to run .ts code.

AWS settings

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.

Deploy stepts

  1. Run npm run build to compile .ts to .js into dist folder. It will also copy package.json into dist folder in order to run Claudia.js.

    If you are using Windows OS, please run npm run build-win instead.

  2. Run npm run create to initialize Claudia.js. Claudia.js will install packages, zip files, upload to Lambda, and setup API Gateway.

    ⚠️ The --region option is mandatory for the create command, and the package.json uses us-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.

  3. Run npm run update to update api if you have done npm run create before. Be careful to keep claudia.json into dist folder. Claudia will generate it after creating api, and use it to update api.

    See more detail in Claudia.js update command.

Testing

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.

Example API

see API.md for API Usages

About

An easy way to make a serverless application with Node.js, TypeScript, and Claudia.js on Amazon Web Services (AWS).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published