-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (28 loc) · 860 Bytes
/
app.js
File metadata and controls
34 lines (28 loc) · 860 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
import express from 'express';
import morgan from 'morgan';
import Prisma from '@prisma/client';
const app = express();
const port = process.env.PORT || 3000
const env = process.env.NULLSTONE_ENV || 'local';
const { PrismaClient } = Prisma;
const prisma = new PrismaClient();
app.use(morgan('combined'))
app.use(express.static('public'));
app.get('/', function (req, res) {
res.redirect('/index.html');
})
app.get('/todos', async (req, res) => {
try {
const todos = await prisma.todos.findMany()
res.json({ data: todos })
} catch (e) {
console.log(e)
res.status(500)
res.json({ error: e.message })
}
})
const server = app.listen(port, () => {
const host = server.address().address;
const port = server.address().port;
console.log(`Example app listening at http://${host}:${port}`);
});