Skip to content

mongoconection #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions node-api/.env.example

This file was deleted.

6 changes: 3 additions & 3 deletions node-api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import bodyParser from "body-parser";
import cors from "cors";
import dotenv from "dotenv";
import "./passport.js";
import { dbConnect } from "./mongo";
import { meRoutes, authRoutes } from "./routes";
import { dbConnect } from "./mongo/index.js";
import { meRoutes, authRoutes } from "./routes/index.js";
import path from "path";
import * as fs from "fs";
import cron from "node-cron";
import ReseedAction from "./mongo/ReseedAction";
import ReseedAction from "./mongo/ReseedAction.js";

dotenv.config();

Expand Down
31 changes: 29 additions & 2 deletions node-api/src/mongo/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
import mongoose from "mongoose";
import dotenv from "dotenv";
import { MongoClient, ServerApiVersion } from 'mongodb';

dotenv.config();

export const dbConnect = () => {
export const dbConnect = async () => {
// console.log(process.env.MONGO_PASS)
// const uri = `mongodb+srv://asiyabatool987:${encodeURIComponent(process.env.MONGO_PASS)}@cluster0.3y2vgwn.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0`;

// // Create a MongoClient with a MongoClientOptions object to set the Stable API version
// const client = new MongoClient(uri, {
// serverApi: {
// version: ServerApiVersion.v1,
// strict: true,
// deprecationErrors: true,
// }
// });

// async function run() {
// try {
// // Connect the client to the server (optional starting in v4.7)
// await client.connect();
// // Send a ping to confirm a successful connection
// await client.db("admin").command({ ping: 1 });
// console.log("Pinged your deployment. You successfully connected to MongoDB!");
// } finally {
// // Ensures that the client will close when you finish/error
// await client.close();
// }
// }
// run().catch(console.dir);

mongoose.connection.once("open", () => console.log("DB connection"));
return mongoose.connect(
`mongodb+srv://${process.env.DB_LINK}?retryWrites=true&w=majority`,
`mongodb+srv://asiyabatool987:${encodeURIComponent(process.env.MONGO_PASS)}@cluster0.3y2vgwn.mongodb.net`,
{ keepAlive: true }
);
};
2 changes: 1 addition & 1 deletion node-api/src/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import passportJWT from "passport-jwt";
import dotenv from "dotenv";
import passport from "passport";

import { userModel } from "./schemas/user.schema";
import { userModel } from "./schemas/user.schema.js";
const JWTStrategy = passportJWT.Strategy;
dotenv.config();

Expand Down
2 changes: 1 addition & 1 deletion node-api/src/routes/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
loginRouteHandler,
registerRouteHandler,
resetPasswordRouteHandler,
} from "../../services/auth";
} from "../../services/auth/index.js";

const router = express.Router();

Expand Down
6 changes: 3 additions & 3 deletions node-api/src/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import userRoutes from './users';
import meRoutes from './me';
import authRoutes from './auth';
import userRoutes from './users/index.js';
import meRoutes from './me/index.js';
import authRoutes from './auth/index.js';

export { userRoutes, meRoutes, authRoutes };
2 changes: 1 addition & 1 deletion node-api/src/routes/me/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import passport from "passport";
import jwt from 'jsonwebtoken';

const router = express.Router();
import { getProfileRouteHandler, patchProfileRouteHandler } from "../../services/me";
import { getProfileRouteHandler, patchProfileRouteHandler } from "../../services/me/index.js";

// get user's profile
router.get("/", passport.authenticate('jwt',{session: false}), (req, res) => {
Expand Down
4 changes: 2 additions & 2 deletions node-api/src/services/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dotenv from "dotenv";
import nodemailer from "nodemailer";
import randomToken from "random-token";
import bcrypt from "bcrypt";
import { userModel } from "../../schemas/user.schema";
import { passwordResetModel } from "../../schemas/passwordResets.schema";
import { userModel } from "../../schemas/user.schema.js";
import { passwordResetModel } from "../../schemas/passwordResets.schema.js";
import jwt from 'jsonwebtoken';

dotenv.config();
Expand Down
2 changes: 1 addition & 1 deletion node-api/src/services/me/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bcrypt from "bcrypt";
import dotenv from 'dotenv';
import { userModel } from "../../schemas/user.schema";
import { userModel } from "../../schemas/user.schema.js";
import jwt from 'jsonwebtoken';

dotenv.config();
Expand Down