For applications meant to use the same space consistently, open an existing
space each time Flatfile is opened. This suits situations where consistently
editing a dataset is preferred.
If you have already tried our Embed a New Space guide you will
notice this guide departs heavily, so you will want to create this in a new
directory, as translation would be more difficult than creating from scratch.
To complete this tutorial, you'll need to retrieve your
Secret key
from your development environment.
Note: Unlike the Publishable Key, the Secret Key shouldn’t be passed through
the browser as it will have full access. This is why we are showing this
example in a server-side call.
Follow prompts from the new command.
ng new create-flatfile-angular-embed
cd create-flatfile-angular-embed
npm i
Install Packages
npm i @flatfile/api @flatfile/listener @flatfile/plugin-record-hook @flatfile/angular-sdk @flatfile/plugin-record-hook @flatfile/listener express && npm i --save-dev concurrently nodemon ts-node
Lets create the server that will act as the backend of the application. This
will be necessary to serve the pages as well as get the existing space, as due
to security reasons the Secret Key cannot be exposed to the browser at any time.
You’ll want to replace the token value with your secret key or api token.
server/index.ts
import express from "express";import { FlatfileClient } from "@flatfile/api";const port = 3000;const app = express();app.get('/api/spaces/:id', async (_req, res)=>{ const {id} = _req.params; const flatfile = new FlatfileClient({ token: 'secret_key', environment: 'https://platform.flatfile.com/api/v1', }); try { const space = await flatfile.spaces.get(id); res.json({ space }); } catch (error) { console.error("Error retrieving space:", error); res.status(500).json({ error: "Failed to retrieve space" }); }})app.listen(port, () => { console.log("Server listening on port", port);});