App.js

mail@pastecode.io avatar
unknown
javascript
a year ago
1.1 kB
9
Indexable
Never
//importing packages and modules
import express from 'express';
import dotenv from 'dotenv';
dotenv.config();
import cors from 'cors';
import passport from 'passport';
import session from 'express-session';

import connectDB from './config/connect.js';
import authRoute from './routes/authRoute.js';
import applicationRoute from './routes/applicationRoutes.js';

import './strategies/google.js'

//all consts
const app = express();
const port = process.env.PORT || 5000;

//db connect and start listening
connectDB();

//set up session
app.use(session({
    secret: process.env.SESSION_SECRET,
    resave: false,
    saveUninitialized: false
}))

//set up passport and session
app.use(passport.initialize());
app.use(passport.session());

//middlewares
app.use(cors());
app.use(express.json());

//routes
app.use('/api/auth', authRoute);
app.use('/api/applications', applicationRoute);

//home route
app.get('/', (req, res) => {
    res.send('Welcome to the server');
});

app.listen(port, () => {
    console.log(`Server is running on http://localhost:${port}`);
});