Giter Site home page Giter Site logo

gong-hao / ts-node-claudia Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 3.0 120 KB

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

TypeScript 100.00%
typescript nodejs express mongodb claudiajs aws aws-lambda aws-apigateway nodemon mocha

ts-node-claudia's Introduction

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

ts-node-claudia's People

Contributors

gong-hao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ts-node-claudia's Issues

Improve documentation about region in package.json

Hello,
Thanks for your work, this is awesome.
I think it would be nice to say that the AWS region is hardcoded in the package.json npm create command. It should be fixed if you want to deploy in another region.
Thanks for that.

A couple comments and a question

Thanks for doing this. It is really helpful!

  1. You may want to add the .vscode to .gitignore. When I pulled it down, my vscode fonts went wonky and it took me a bit to figure out what happened.

  2. I'm guessing this was developed on windows? You may want to add a note to the readme that on linus/osx the build command in package.json should use "cp" instead of "copy".

Now my question:

To change the name of my lambda, do I just need to change "name" and "role" in claudia.json?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.