-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (42 loc) · 1.33 KB
/
app.js
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
const path = require("path");
const express = require("express");
const fs=require("fs");
const app = express();
const mongoose = require('mongoose');
const bodyparsor=require('body-parser');
main().catch(err => console.log(err));
const port = 80;
async function main() {
await mongoose.connect('mongodb://127.0.0.1:27017/details',{ useNewUrlParser: true, useUnifiedTopology: true });
console.log("connected")
}
const loginSchema = new mongoose.Schema({
username: String,
password:String
});
const Userlogin = mongoose.model('Loguser', loginSchema);
app.use(express.static(path.join(__dirname, '/')));
app.use(express.urlencoded());
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname,'/', 'index.html'));
});
app.get("/about", (req, res) => {
res.sendFile(path.join(__dirname,'/', 'about.html'));
});
app.get("/startups", (req, res) => {
res.sendFile(path.join(__dirname,'/', 'about.html'));
});
app.get("/lawyers", (req, res) => {
res.sendFile(path.join(__dirname,'/', 'about.html'));
});
app.post('/submit', (req, res) => {
let logindata =new Userlogin(req.body);
logindata.save().then(()=>{
res.redirect('/');
}).catch(()=>{
res.status(404).send("Error 404 not found");
});
});
app.listen(port, () => {
console.log(`Port 80 running at http://localhost//${port}`);
});