https://github.com/digitalocean/sample-functions-typescript-helloworld
https://github.com/digitalocean/sample-functions-typescript-helloworld
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/digitalocean/sample-functions-typescript-helloworld
- Owner: digitalocean
- Created: 2022-02-14T11:54:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-05-24T19:34:31.000Z (about 3 years ago)
- Last Synced: 2025-06-11T01:09:26.064Z (about 1 year ago)
- Language: TypeScript
- Size: 3.91 KB
- Stars: 8
- Watchers: 10
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sample Function: TypeScript "Hello World"
## Introduction
This repository contains a sample "Hello World" function written in TypeScript. You can deploy it on DigitalOcean's App Platform as a Serverless Function component or as a standalone Function. Documentation is available at https://docs.digitalocean.com/products/functions.
### Requirements
* You need a DigitalOcean account. If you don't already have one, you can sign up at [https://cloud.digitalocean.com/registrations/new](https://cloud.digitalocean.com/registrations/new).
* To deploy from the command line, you will need the [DigitalOcean `doctl` CLI](https://github.com/digitalocean/doctl/releases).
## Deploying the Function
```bash
# clone this repo
git clone git@github.com:digitalocean/sample-functions-typescript-helloworld.git
```
```
# deploy the project, using a remote build so that compiled executable matched runtime environment
> doctl serverless deploy sample-functions-typescript-helloworld --remote-build
Deploying 'sample-functions-typescript-helloworld'
to namespace 'fn-...'
on host 'https://faas-...'
Submitted action 'hello' for remote building and deployment in runtime typescript:default (id: ...)
Deployed functions ('doctl sls fn get --url' for URL):
- sample/hello
```
## Using the Function
### `doctl` CLI
```bash
doctl serverless functions invoke sample/hello
```
```json
{
"body": "Hello stranger!"
}
```
### `doctl` CLI with a request Body
```bash
doctl serverless functions invoke sample/hello -p name:Sammy
```
```json
{
"body": "Hello Sammy!"
}
```
### `curl`
```bash
curl $(doctl sls fn get sample/hello --url)
```
```
Hello stranger!
```
💡 The output above is not in json format because it's performing an HTTP get directly and the body of the function does not return a json object, but a plain string.
### Learn More
You can learn more about Functions and App Platform integration in [the official App Platform Documentation](https://www.digitalocean.com/docs/app-platform/).