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.
|
|
|
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 = 4002;
|
|
|
|
|
|
|
|
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(cors());
|
|
|
|
app.use(express.json());
|
|
|
|
app.use(express.urlencoded({extended : true}));
|
|
|
|
app.use(express.static('public'));
|
|
|
|
|
|
|
|
app.use("/b2/users", userRoutes);
|
|
|
|
app.use("/b2/products", productRoutes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// run the server to a specific port:
|
|
|
|
app.listen(port, () => {
|
|
|
|
console.log(`API is now online on port ${port}!`);
|
|
|
|
})
|