Show how to terminate an HTTP connection in Node.js

## Explore further


For detailed documentation that includes this code sample, see the following:

- [The Node.js Runtime](https://docs.cloud.google.com/functions/1stgendocs/concepts/nodejs-runtime.md.txt)

## Code sample

### Node.js


To authenticate to Cloud Run functions, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```javascript
// OK: await-ing a Promise before sending an HTTP response
await Promise.resolve();

// WRONG: HTTP functions should send an
// HTTP response instead of returning.
return Promise.resolve();

// HTTP functions should signal termination by returning an HTTP response.
// This should not be done until all background tasks are complete.
res.status(200).send();

// WRONG: this may not execute since an
// HTTP response has already been sent.
return Promise.resolve();
```

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples.md.txt?product=cloudfunctions).