Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,8 @@ This directory contains advanced docs around the Functions Framework.
- [Debugging Functions](debugging.md)
- [Running and Deploying Docker Containers](docker.md)
- [Writing a Function in Typescript](typescript.md)
- [ES Modules](esm.md)

## TODO Docs

- TODO: Run Multiple Cloud Functions [#23](https://github.com/GoogleCloudPlatform/functions-framework-nodejs/issues/23)

## Debugging functions

The Functions Framework works with standard tooling that you might use when writing a function for a Node.js environment. You can attach a debugger to your function by following these steps.

1. Write an `index.js` file containing your Node.js function:

```js
exports.helloWorld = (req, res) => {
res.send('Hello, World');
};
```

2. Install the Functions Framework:

```sh
npm install @google-cloud/functions-framework
```

3. Run `node`, enable the inspector and run the Functions Framework:

```sh
node --inspect node_modules/@google-cloud/functions-framework --target=helloWorld
...
Debugger listening on ws://127.0.0.1:9229/5f57f5e9-ea4b-43ce-be1d-6e9b838ade4a
For help see https://nodejs.org/en/docs/inspector
Serving function...
Function: helloWorld
URL: http://localhost:8080/
```

You can now use an IDE or other tooling to add breakpoints, step through your code and debug your function.
- Run Multiple Cloud Functions [#23](https://github.com/GoogleCloudPlatform/functions-framework-nodejs/issues/23)
57 changes: 57 additions & 0 deletions docs/esm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Using ES Modules

The Functions Framework >= `1.9.0` supports loading your code as an ES Module.

ECMAScript modules (ES modules or ESM) are a TC39 standard, unflagged feature in Node >=14 for loading JavaScript modules. As opposed to CommonJS, ESM provides an asynchronous API for loading modules and provides a very commonly adopted syntax improvement via `import` and `export` statements.

## Example

Before:

```js
exports.helloGET = (req, res) => {
res.send('No ESM.');
};
```

After:

```js
export const helloGET = (req, res) => {
res.send('ESM!');
};
```

## Quickstart

Create a `package.json` file:

```json
{
"type": "module",
"scripts": {
"start": "functions-framework --target=helloGET"
},
"main": "index.js",
"dependencies": {
"@google-cloud/functions-framework": "^1.9.0"
}
}
```

Create a `index.js` file:

```js
export const helloGET = (req, res) => {
res.send('ESM!');
};
```

Install dependencies and start the framework:

```sh
npm i
npm start
```

Go to `localhost:8080/` and see your function execute!