Express.js
In order for Stringtale to work, a back-end server is required. One of our supported options is Express.js. In this guide we’ll go over the manual implementation of Stringtale using Express.js.
Manual implementation
To use Stringtale in your Express.js application you can either use stringtale init from our CLI or
execute the following steps manually.
-
Install the
@stringtale/expressand@stringtale/reactpackages in your project using your package manager.Terminal window npm install @stringtale/express @stringtale/reactTerminal window # If you're using a monorepo with workspaces, add it to the right workspaceyarn add @stringtale/express @stringtale/reactTerminal window pnpm install @stringtale/express @stringtale/react -
Add the
/api/stringtaleroute to your Express.js app. Example:import express from 'express'import { setupRoute } from "@stringtale/express"const app = express()app.all('/api/stringtale', setupRoute({apiKey: process.env.STRINGTALE_API_KEY!})) -
Add
STRINGTALE_API_KEYto your environment (for example a.envfile). This API key can be obtained from the Stringtale Dashboard.STRINGTALE_API_KEY=YOUR_API_KEYFor more information on how to obtain an API key, please refer to the obtaining an API key guide.
-
Modify the
app.js/app.tsxof your React application to provide the Stringtale context to your application.import { StringtaleProvider } from "@stringtale/react"import "@stringtale/react/styles.css"function App() {return (<StringtaleProvider apiRoute="https://www.example.com/api/stringtale"><div className="App" /></StringtaleProvider>)}export default AppFor more information about Contexts and Context Providers see this React blogpost and the React documentation.
-
You’re now ready to use Stringtale in your project. For more information on how to use Stringtale with React see our React documentation.