-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mjs
60 lines (51 loc) · 1.35 KB
/
index.mjs
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
51
52
53
54
55
56
57
58
59
60
import express from "express";
import path from "path";
import cookieParser from "cookie-parser";
import session from "express-session";
import multer from "multer";
import nodemailer from "nodemailer";
import routes from "./routes/index.js";
// Create Express app
const app = express();
// Set up middleware
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cookieParser());
app.use(session({
secret: "secret",
resave: false,
saveUninitialized: true
}));
// Set views directory and view engine
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
// Set up multer for file uploads
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'uploads/');
},
filename: (req, file, cb) => {
cb(null, file.originalname);
}
});
const upload = multer({ storage: storage });
// Set up nodemailer for sending emails
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'your_password'
}
});
// Middleware to attach nodemailer transporter to request object
app.use((req, res, next) => {
req.transporter = transporter;
next();
});
// Set up routes
app.use("/", routes);
// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});