-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from SuperAayush/server-setup
feat:database connected
- Loading branch information
Showing
9 changed files
with
3,870 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.env | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import express from "express"; | ||
import Post from "../Schema/test.js"; | ||
|
||
const Router = express.Router(); | ||
|
||
let allpost; | ||
|
||
Router.post("/check", async (req, res) => { | ||
try { | ||
allpost = await req.body; | ||
|
||
console.log(req.body); | ||
const data = await new Post(req.body); | ||
|
||
data.save(); | ||
res.status(200).json(data); | ||
} catch (err) { | ||
res.status(500).json(err); | ||
} | ||
}); | ||
|
||
export default Router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const PostSchema = new mongoose.Schema({ | ||
title: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
|
||
const Post = mongoose.model("posts", PostSchema); | ||
|
||
export default Post; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const connection = async (URL) => { | ||
try { | ||
await mongoose.connect(URL, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
console.log("Connected To MongoDb"); | ||
} catch (error) { | ||
console.log("Error While Connecting to MongoDb", error); | ||
} | ||
}; | ||
|
||
export default connection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import express from "express"; | ||
import connection from "./database/DB.js"; | ||
import Router from "./Routes/Routes.js"; | ||
import bodyParser from "body-parser"; | ||
import dotenv from "dotenv"; | ||
const app = express(); | ||
|
||
dotenv.config(); | ||
|
||
app.use(bodyParser.json({ extended: true })); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
|
||
const URL = process.env.AZURE_URL; | ||
|
||
const PORT = 8000; | ||
|
||
app.use("/", Router); | ||
|
||
app.listen(PORT, () => console.log("Server is running")); | ||
|
||
connection(URL); |
Oops, something went wrong.