-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f401fc
commit 72d9d5a
Showing
1,324 changed files
with
344,181 additions
and
6 deletions.
There are no files selected for viewing
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,2 @@ | ||
MONGO_URI: "mongodb+srv://rjReactDev:Deadrjs%[email protected]/?retryWrites=true&w=majority"; | ||
PORT:4040 |
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 |
---|---|---|
@@ -1,12 +1,50 @@ | ||
const port = 4040 | ||
|
||
const express = require('express') | ||
const app = express() | ||
const morgan = require('morgan') | ||
const env = require('dotenv') | ||
const mongoose=require('mongoose') | ||
const { MongoClient, ServerApiVersion } = require('mongodb'); | ||
env.config() | ||
const port = process.env.PORT || 4040 | ||
const uri ="mongodb+srv://rjReactDev:[email protected]/?retryWrites=true&w=majority"; | ||
|
||
//db connection | ||
// mongoose.connect(uri) | ||
// .then(()=>console.log('Db connected.')) | ||
// mongoose.connection.on('error',err=>{ | ||
// console.log(`db connection has some error: ${err.message}`) | ||
// }) | ||
|
||
const client = new MongoClient(uri, { | ||
serverApi: { | ||
version: ServerApiVersion.v1, | ||
strict: true, | ||
deprecationErrors: true, | ||
} | ||
}); | ||
async function run() { | ||
try { | ||
// Connect the client to the server (optional starting in v4.7) | ||
await client.connect(); | ||
// Send a ping to confirm a successful connection | ||
// await client.db("admin").command({ ping: 1 }); | ||
console.log("Pinged your deployment. You successfully connected to MongoDB!"); | ||
} finally { | ||
// Ensures that the client will close when you finish/error | ||
await client.close(); | ||
} | ||
} | ||
run().catch(console.dir); | ||
|
||
//const postRoutes =require('./routes/post') | ||
|
||
//using destructuring method | ||
const { getPosts } = require('./routes/post') | ||
//const { getPosts } = require('./routes/post') | ||
|
||
//app.get("/", getPosts) | ||
//using controller | ||
const postRouter = require('./routes/post') | ||
|
||
// const myOwnMiddleWare = (req, res, next) => { | ||
// console.log("my own ") | ||
|
@@ -17,7 +55,8 @@ const { getPosts } = require('./routes/post') | |
|
||
app.use(morgan('dev')) | ||
|
||
app.get("/", getPosts) | ||
app.use("/", postRouter) | ||
|
||
app.listen(port, () => [ | ||
console.log(`Server listening on port : ${port}`) | ||
]) |
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,8 @@ | ||
exports.getPosts = (req, res) => { | ||
// res.send('<h1>Welcome to Node js Server</h1>') | ||
|
||
//need to json return as response | ||
res.json({ | ||
posts: [{ title: 'ReactJs' }, { title: 'Redux' }, { title: 'Javascript' }, { title: 'node' }] | ||
}) | ||
} |
Oops, something went wrong.