Project Setup Guide
Project Setup Guide
Initialize Node.js:
```bash
npm init -y
```
```env
DB_HOST=localhost
DB_USER=wpr
DB_PASS=fit2024
DB_NAME=wpr<student_id>
PORT=8000
```
This script sets up the MySQL database and initializes it with the required data:
```js
const mysql = require('mysql2');
require('dotenv').config();
const setupDatabase = \`
CREATE DATABASE IF NOT EXISTS ${dbName};
USE ${dbName};
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(255),
email VARCHAR(255) UNIQUE,
password VARCHAR(255)
);
CREATE TABLE IF NOT EXISTS emails (
id INT AUTO_INCREMENT PRIMARY KEY,
sender_id INT,
recipient_id INT,
subject VARCHAR(255),
body TEXT,
attachment VARCHAR(255),
sent_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (sender_id) REFERENCES users(id),
FOREIGN KEY (recipient_id) REFERENCES users(id)
);
INSERT INTO users (full_name, email, password) VALUES
('User One', '[email protected]', '123'),
('User Two', '[email protected]', '123456'),
('User Three', '[email protected]', 'password');
INSERT INTO emails (sender_id, recipient_id, subject, body) VALUES
(1, 2, 'Hello', 'This is an email body'),
(2, 1, 'Hi there', 'This is another email body');
\`;
```js
const express = require('express');
const cookieParser = require('cookie-parser');
const dotenv = require('dotenv');
const path = require('path');
const authRoutes = require('./routes/auth');
const emailRoutes = require('./routes/email');
dotenv.config();
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, 'public')));
// Routes
app.use('/', authRoutes);
app.use('/emails', emailRoutes);
module.exports = router;
```
module.exports = router;
```
Create EJS templates under the `views` folder for `signin`, `signup`, `inbox`, etc., to render
HTML forms and pages based on user actions.