You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
863 B
JavaScript

const express = require("express");
const mongoose = require("mongoose");
const userRoutes = require("./routes/userRoutes.js");
const productRoutes = require("./routes/productRoutes.js");
const cors = require("cors");
const port = 2024;
const app = express();
mongoose.connect('mongodb+srv://admin:admin@b330juan.sxv2kqg.mongodb.net/Capstone-2?retryWrites=true&w=majority');
let connect = mongoose.connection;
connect.on("error", console.error.bind(console, "Connection error!"));
connect.once("open", () => {
console.log("Connected with the Database!");
});
// Middlewares
app.use(express.json());
app.use(express.urlencoded({extended : true}));
app.use(cors());
app.use("/users", userRoutes);
app.use("/products", productRoutes);
// run the server to a specific port:
app.listen(port, () => {
console.log(`API is now online on port ${port}!`);
})