Skip to content

Commit 6c7da3a

Browse files
committed
prod and dev env setup
1 parent 918597a commit 6c7da3a

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
node_modules
2-
.env
2+
*.env

api/article/controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exports.addArticle = asyncHandler(async (req, res, next) => {
6060
// @req-type : GET
6161
// @description : Get all articles
6262
exports.getArticles = asyncHandler(async (req, res, next) => {
63-
const articles = await Article.find({ isAuthentic: true }).sort({ _id: -1 });
63+
const articles = await Article.find({ isAuthentic: true }).sort({ _id: -1 }).limit(10);
6464
return res.status(200).json({
6565
success: true,
6666
count: articles.length,
@@ -136,6 +136,7 @@ exports.authenticateArticle = asyncHandler(async (req, res, next) => {
136136
});
137137
}
138138
await Article.findByIdAndUpdate(articleId, { isAuthentic: true });
139+
139140
res.status(200).json({
140141
success: true,
141142
message: 'Article approved successfully!'
@@ -178,10 +179,9 @@ const sendMail = async (body, encryptedString) => {
178179
encryptedString
179180
}
180181
const html = compileTemplate(htmlTemplate, params);
181-
182-
let info = await transporter.sendMail({
182+
await transporter.sendMail({
183183
from: '"Anubhav" <[email protected]>', // sender address
184-
to: [process.env.VERIFY_MAIL], // list of receivers
184+
to: [process.env.VERIFY_MAIL_DEV], // list of receivers
185185
subject: `Anubhav - ${body.title}`, // Subject line
186186
html
187187
});

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"main": "server.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"start": "nodemon server.js"
8+
"start": "NODE_ENV=prod node server.js",
9+
"dev": "NODE_ENV=dev nodemon server.js",
10+
"prod": "NODE_ENV=prod node server.js"
911
},
1012
"keywords": [
1113
"AITOSS",

server.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ const hpp = require('hpp');
77
const fileUpload = require('express-fileupload');
88
const rateLimit = require('express-rate-limit');
99
// load env variables
10-
require('dotenv').config();
10+
let envPath;
11+
12+
if(process.env.NODE_ENV == 'prod')
13+
envPath = './prod.env';
14+
else
15+
envPath = './dev.env';
16+
17+
require('dotenv').config({path: envPath});
1118
const path = require('path');
1219
const helmet = require('helmet');
1320
const apiRouter = require('./api');
@@ -67,7 +74,6 @@ app.get("*", (req, res) => {
6774

6875
app.use(errorHandler);
6976

70-
7177
const PORT = process.env.PORT || 5000;
7278
app.listen(PORT, console.log(`Server running on port ${PORT}`.yellow.bold));
7379

0 commit comments

Comments
 (0)