-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (26 loc) · 767 Bytes
/
Copy pathapp.js
File metadata and controls
32 lines (26 loc) · 767 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
const express = require('express');
const dotenv = require('dotenv');
const db = require('./database');
const userRoutes = require('./routes/users');
// Load environment variables
dotenv.config();
const app = express();
// Middleware
app.use(express.json());
app.use(express.static('public'));
// Routes
app.use('/api/users', userRoutes);
// Basic route for testing
app.get('/', (req, res) => {
res.json({ message: 'Welcome to the Node.js SQLite API' });
});
// Initialize database and start server
const PORT = process.env.PORT || 3000;
db.init().then(() => {
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
}).catch(err => {
console.error('Failed to initialize database:', err);
process.exit(1);
});