-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (38 loc) · 1.02 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import express from "express";
import Neo4jTempDB from "neo4j-temp-db";
import neo4j from "neo4j-driver";
import dotenv from "dotenv";
dotenv.config();
const app = express();
app.use(express.urlencoded({ extended: true }));
app.set("view engine", "ejs");
const tempDb = new Neo4jTempDB(
process.env.NEO4J_URI,
neo4j.auth.basic(
process.env.NEO4J_USER,
process.env.NEO4J_PASSWORD
)
);
const queries = {};
app.use('^/$', async (req, res) => {
let { cypher, tempDbName } = req.body;
if (!tempDbName) {
tempDbName = await tempDb.createDatabase();
}
if (!queries[tempDbName]) {
queries[tempDbName] = [];
}
if (cypher && tempDbName) {
const result = await tempDb.runCypherOnDatabase(tempDbName, "3.5", cypher);
queries[tempDbName].push({ cypher, result });
}
queries[tempDbName].reverse();
res.render("index", {
tempDbName,
queries: queries[tempDbName]
});
});
const port = process.env.PORT || 3000;
app.listen({ port }, () => {
console.log(`Ready at http://localhost:${port}`);
});