You can integrate PreviewLinks with any Node.js server side application. Here's an Express.js example serving a simple HTML template:
const express = require('express')
const { PreviewLinks } = require('@previewlinks/node-previewlinks')
const app = express()
const previewlinks = new PreviewLinks({ apiToken: '<YOUR_API_TOKEN>' })
app.get('/', (request, response) => {
const image = previewlinks.signedImageUrl({
templateId: 732,
fields: {
'previewlinks': 'Hello from Node.js',
},
})
return response.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Your Application</title>
<meta property="og:image" content="${image}" />
<meta name="twitter:image" content="${image}" />
</head>
<body>
<h1>Hello from Node.js</h1>
</body>
</html>
`)
})
app.listen(1337)