| 1234567891011121314151617181920212223242526 |
- const express = require('express');
- const mongoose = require('mongoose');
- const dotenv = require('dotenv');
- const authRoutes = require('./routes/auth');
- const invoiceRoutes = require('./routes/invoices');
- dotenv.config();
- const app = express();
- app.use(express.json());
- mongoose.connect(process.env.MONGO_URI, {
- useNewUrlParser: true,
- useUnifiedTopology: true
- }).then(() => console.log('Connected to MongoDB')).catch(err => console.error(err));
- app.use('/auth', authRoutes);
- app.use('/invoices', invoiceRoutes);
- app.use((err, req, res, next) => {
- console.error(err.stack);
- res.status(500).json({ error: 'Something went wrong!' });
- });
- const PORT = process.env.PORT || 3000;
- app.listen(PORT, () => console.log(`Server running on port ${PORT}`));
|