ecomm/src/index.ts

27 lines
582 B
TypeScript
Raw Normal View History

import express from 'express';
2023-06-08 16:03:27 +00:00
import mongoose from 'mongoose';
2023-06-08 15:50:54 +00:00
import userRoutes from './routes/user';
2023-06-08 16:03:27 +00:00
const env = require('dotenv').config().parsed;
const app = express();
2023-06-08 15:50:54 +00:00
const PORT = 3000;
app.use(express.json());
2023-06-08 16:03:27 +00:00
// Connect to MongoDB using Mongoose
mongoose.connect(env.DATABASE_URL);
2023-06-08 16:03:27 +00:00
const db = mongoose.connection;
2023-06-08 16:03:27 +00:00
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
db.once('open', () => {
console.log('Connected to MongoDB');
});
2023-06-08 16:03:27 +00:00
app.use('/users', userRoutes);
2023-06-08 16:03:27 +00:00
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});