-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
45 lines (36 loc) · 1.21 KB
/
app.js
File metadata and controls
45 lines (36 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require("dotenv").config();
const express=require('express');
const mongoose=require("mongoose");
const path =require('path');
const app=express();
//this helps the person to parse the url encoded information and the converts the req.body() into json format
app.use(express.urlencoded({extended:false}));
//express.json() and bodyParser.json() dose the same job
app.use(express.json());
// app.use(bodyParser.json());
const mailRouter=require("./routes/mailRouter");
app.set("views",path.join(__dirname,'views'))
app.use('/static',express.static('static'))
app.set("view engine","pug");
mongoose.connect(process.env.MONGOURI,
{
dbName:"newsletter",//giving the database name
user:process.env.USER,
pass:process.env.PASS,
useNewUrlParser:true,
useUnifiedTopology:true,
useFindAndModify:false
})
.then(()=>{
console.log("Mongodb connected...");
})
.catch(()=>{
console.log("Connection failed...")
});
app.use('/',mailRouter);
// error handling
// app.use((req,res,next)={
// const err = new Error(404,"Some error occured");
// })
app.listen(4343 || process.env.PORT,()=>{
console.log("The server started running on the port 80")});