Skip to content

Commit a3db905

Browse files
adding .env
1 parent 18be6e7 commit a3db905

File tree

6 files changed

+17
-3
lines changed

6 files changed

+17
-3
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DATABASE_URL=mongodb://localhost

.gitignore

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ To install project run the command in the terminal
3636

3737
## Features
3838

39+
- upload file
3940
- Code copy to clipboard button
4041
- see others codeboxes
4142

app.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
if (process.env.NODE_ENV !== 'production') {
2+
require('dotenv').config()
3+
}
4+
15
const express = require('express')
26
const mongoose = require('mongoose')
37
const Code = require('./models/code.js')
48
const app = express()
59

610
// connect to the mongo database
7-
mongoose.connect('mongodb://localhost/')
11+
mongoose.connect(process.env.DATABASE_URL,
12+
{ useNewUrlParser: true })
813

914
// middlewares
1015
app.use(express.urlencoded({ extended: true }))
@@ -69,7 +74,7 @@ app.get('/about', (req, res)=>{
6974
res.render('about', { title: 'About' })
7075
})
7176

72-
app.listen(3000)
77+
app.listen(process.env.PORT || 3000)
7378

7479
app.use((req, res)=>{
7580
res.render("404", { title: '404 Page not found'})

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13+
"dotenv": "^10.0.0",
1314
"ejs": "^3.1.6",
1415
"express": "^4.17.1",
1516
"mongoose": "^6.0.8",

0 commit comments

Comments
 (0)