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 with the app router you can either use stringtale init
from our CLI or
execute the following steps manually.
-
Install the
@stringtale/express
and@stringtale/react
package 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/stringatale
route to your routes file in Express.JS. Example:import express from 'express'import { setupRoute } from "@stringtale/express"const app = express()app.all('/api/stringtale', setupRoute({apiKey: process.env.STRINGTALE_API_KEY!}))For more information on how to obtain an API key, please refer to the obtaining an API key guide.
-
Modfiy the
app.js
/app.tsx
of 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.