-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
38 lines (29 loc) · 908 Bytes
/
app.js
File metadata and controls
38 lines (29 loc) · 908 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
const express = require('express');
const sqlite3 = require('sqlite3').verbose(); // Verbose for easier debugging
const app = express();
const port = 3000;
// Create an in-memory database
const db = new sqlite3.Database(':memory:', (err) => {
if (err) {
return console.error(err.message);
}
console.log('Connected to the in-memory SQLite database.');
});
// Create a table
db.run('CREATE TABLE users (email TEXT, password TEXT)', (err) => {
if (err) {
return console.error(err.message);
}
console.log('Table created.');
});
app.get('/', (req, res) => {
res.send('Hello, World!');
});
const server = app.listen(port, () => {
console.log(`Listening at http://localhost:${port}`);
});
module.exports = {
app: app, // Export app for testing
server: server, // Export server instance for testing
db: db // Export SQLite db instance for testing
};