Skip to content

digitalocean/sample-functions-nodejs-helloworld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sample Function: Node.js "Hello World"

Introduction

This repository contains a sample function written in Node.js JavaScript. 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

Deploying the Function

# clone this repo
git clone [email protected]:digitalocean/sample-functions-nodejs-helloworld.git
# deploy the project, using a remote build so that compiled executable matched runtime environment
doctl serverless deploy sample-functions-nodejs-helloworld --remote-build

The output from the deploy command will resemble the following.

Deploying 'sample-functions-nodejs-helloworld'
  to namespace 'fn-...'
  on host '...'
Submitted function 'sample/hello' for remote building and deployment in runtime nodejs:default (id: ...)
Processing of action 'sample/hello' is still running remotely ...
Deployment status recorded in 'sample-functions-nodejs-helloworld/.deployed'

Deployed functions ('doctl sls fn get <funcName> --url' for URL):
  - sample/hello

Using the Function

doctl serverless functions invoke sample/hello

This will return the default response from the function.

{
  "body": "Hello stranger!"
}

You can pass a parameter to your function using the -p command line argument.

doctl serverless functions invoke sample/hello -p name:functions
{
  "body": "Hello functions!"
}

Use this command to retrieve the URL for your function and use it as an API.

doctl sls fn get sample/hello --url

You can use that API directly in your browser, with curl or with an API platform such as Postman. Parameters may be passed as query parameters, or as JSON body. Here are some examples using curl.

curl `doctl sls fn get sample/hello --url`?name=query
curl -H 'Content-Type: application/json' -d '{"name":"body"}' `doctl sls fn get sample/hello --url`

Learn More

You can learn more about Functions by reading the Functions Documentation.

About

No description, website, or topics provided.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •