-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (26 loc) · 754 Bytes
/
server.js
File metadata and controls
35 lines (26 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const express = require("express");
const http = require("http");
const { createClient } = require("@deepgram/sdk");
const dotenv = require("dotenv");
dotenv.config();
const client = createClient(process.env.DEEPGRAM_API_KEY);
const app = express();
const server = http.createServer(app);
app.use(express.static("public/"));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/public/index.html");
});
const getTempToken = async () => {
const { result, error } = await client.auth.grantToken();
if (error) {
throw error;
}
return result;
};
app.get("/token", async (req, res) => {
const token = await getTempToken();
res.json(token);
});
server.listen(3000, () => {
console.log("listening on http://localhost:3000");
});