Skip to content

Commit

Permalink
Merge pull request #3 from SuperAayush/server-setup
Browse files Browse the repository at this point in the history
feat:database connected
  • Loading branch information
AayushShuk1a authored Apr 16, 2022
2 parents c0b8750 + 7d9242d commit a8e06c1
Show file tree
Hide file tree
Showing 9 changed files with 3,870 additions and 0 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^13.5.0",
"express": "^4.17.3",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "5.0.1",
Expand Down
24 changes: 24 additions & 0 deletions server/.gitignore
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*
22 changes: 22 additions & 0 deletions server/Routes/Routes.js
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;
12 changes: 12 additions & 0 deletions server/Schema/test.js
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;
15 changes: 15 additions & 0 deletions server/database/DB.js
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;
21 changes: 21 additions & 0 deletions server/index.js
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);
Loading

0 comments on commit a8e06c1

Please sign in to comment.