This file contains hidden or 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
| const http = require('http'); | |
| const socket = require('socket.io'); | |
| const server = http.createServer(); | |
| const io = socket(server); | |
| server.listen(8080, () => console.log(`Server Running`)) | |
This file contains hidden or 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
| const express = require('express'); | |
| const mongoose = require('mongoose'); | |
| const app = express() | |
| const User = require('./model/user'); | |
| mongoose.connect( | |
| `mongodb+srv://piyushgarg:[email protected]/test?retryWrites=true&w=majority`, | |
| { |
This file contains hidden or 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
| const mongoose = require('mongoose'); | |
| const userSchema = mongoose.Schema({ | |
| name: { | |
| type: String, | |
| required: true, | |
| }, | |
| email:{ | |
| type: String, | |
| required: true, |
This file contains hidden or 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
| const express = require('express'); | |
| const mongoose = require('mongoose'); | |
| const app = express() | |
| mongoose.connect( | |
| `mongodb+srv://piyushgarg:[email protected]/test?retryWrites=true&w=majority`, | |
| { | |
| useNewUrlParser: true, | |
| useUnifiedTopology: true |
This file contains hidden or 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
| const express = require('express'); | |
| const mongoose = require('mongoose'); | |
| const app = express() | |
| mongoose.connect( | |
| `mongodb+srv://piyushgarg:[email protected]/test?retryWrites=true&w=majority`, | |
| { | |
| useNewUrlParser: true, | |
| useUnifiedTopology: true |
This file contains hidden or 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
| const express = require('express'); | |
| const mongoose = require('mongoose'); | |
| const app = express() | |
| mongoose.connect( | |
| `mongodb+srv://piyushgarg:[email protected]/test?retryWrites=true&w=majority` | |
| ) | |
| .then(() => console.log('MongoDB Connect')) | |
| .catch((err) => console.log(`Error Occured ${err}`)) |
This file contains hidden or 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
| const express = require('express'); | |
| const mongoose = require('mongoose'); | |
| const app = express() | |
| app.get('/', (req, res) => { | |
| res.send('Welcome to my API'); | |
| }) |
This file contains hidden or 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
| const express = require('express'); | |
| const app = express() | |
| app.get('/', (req, res) => { | |
| res.send('Welcome to my API'); | |
| }) | |
| app.listen(9000, () => console.log('Server Started at PORT 9000')) |
This file contains hidden or 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
| const LocalStrategy = require('passport-local').Strategy; | |
| module.exports = function(passport){ | |
| passport.use( | |
| new LocalStrategy({usernameField: 'email'}, (email, password, done) => { | |
| // ... do the database stuff with email and passsword and get all the details | |
| // of user. In this case I am hardcoding the user. | |
| const user = { | |
| } |
This file contains hidden or 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
| app.post('/login', passport.authenticate('local'), (req, res) => { | |
| res.send('Login Success') | |
| }) |