create-myexam-app 1.0.27 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  "name": "create-myexam-app",
4
4
 
5
- "version": "1.0.27",
5
+ "version": "1.0.29",
6
6
 
7
7
  "description": "My exam projects",
8
8
 
@@ -0,0 +1,3 @@
1
+ PORT = 5001
2
+ MONGO_URI=mongodb://localhost:27017/SMS
3
+ JWT_SECRET=your_secret_key_here
@@ -2,7 +2,7 @@ const mongoose = require('mongoose');
2
2
 
3
3
  const connectDB = async () => {
4
4
  try {
5
- await mongoose.connect('mongodb://localhost:27017/SMS');
5
+ await mongoose.connect( process.env.MONGO_URI);
6
6
  console.log('MongoDB connected');
7
7
  } catch (error) {
8
8
  console.error('MongoDB connection error:', error);
@@ -1,7 +1,7 @@
1
1
  const bcrypt = require('bcrypt');
2
2
  const jwt = require('jsonwebtoken');
3
3
  const User = require('../models/User');
4
- const JWT_SECRET = 'change_this_to_a_long_random_secret';
4
+ const JWT_SECRET = process.env.JWT_SECRET;
5
5
 
6
6
 
7
7
 
@@ -1,12 +1,8 @@
1
- // this middleware is helping us to protect our routes so that only authenticated users can access the routes
2
- //it is checking if the user is authenticated by checking the token in the header(the header is the part of the request that contains the token)
3
- //if the user is not authenticated, it will return a 401 status code and a message that the user is not authorized
4
- //if the user is authenticated, it will return the user object
5
- //and the user object is the user that is authenticated
1
+
6
2
 
7
3
  const jwt = require('jsonwebtoken');
8
4
  const User = require('../models/User');
9
- const JWT_SECRET = 'change_this_to_a_long_random_secret';
5
+ const JWT_SECRET = process.env.JWT_SECRET;
10
6
 
11
7
  exports.protect = async (req, res, next) => {
12
8
  try {
@@ -1,3 +1,4 @@
1
+ require('dotenv').config();
1
2
  const express = require('express');
2
3
  const cors = require('cors');
3
4
 
@@ -25,7 +26,7 @@ app.use('/api/sales', salesRoutes);
25
26
  app.use('/api/warehouse', warehouseRoutes);
26
27
  app.use('/api/reports', reportRoutes);
27
28
 
28
- const PORT = 5001;
29
+ const PORT = process.env.PORT || 5001
29
30
  app.listen(PORT, () => {
30
31
  console.log(`Server running on http://localhost:${PORT}`);
31
32
  });