You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
here is my code for index.js :-
const express = require('express')
require('./db/mongoose')
const userRouter = require('../src/routers/userRouter')
const taskRouter = require('../src/routers/taskRouter')
const app = express()
const port = process.env.PORT
// app.use((req,res,next)=>
// {
// res.status(503).send('App under maintainance')
// })
app.use(express.json())
app.use(userRouter)
app.use(taskRouter)
app.listen(port,()=>{
console.log('Server is up and running on port ',port)
})
here is my code for index.js :-
const express = require('express')
require('./db/mongoose')
const userRouter = require('../src/routers/userRouter')
const taskRouter = require('../src/routers/taskRouter')
const app = express()
const port = process.env.PORT
// app.use((req,res,next)=>
// {
// res.status(503).send('App under maintainance')
// })
app.use(express.json())
app.use(userRouter)
app.use(taskRouter)
app.listen(port,()=>{
console.log('Server is up and running on port ',port)
})
For userRouter :-
const express = require('express')
const User = require('../models/user-model')
const router = new express.Router()
const { deletemsg } = require('../../email/deletemsg')
const {welcomeEmail} = require('../../email/account')
const sharp = require('sharp')
const auth = require('../middleware/auth')
const multer = require('multer')
router.post('/users',async (req,res)=>{
const user = new User(req.body)
try{
await user.save()
welcomeEmail(user.email,user.name)
const token = await user.generatejwt()
res.status(201).send({user,token})
}catch(e){
res.status(404).send()
}
})
router.post('/users/login',async (req,res)=>
{
const user = await User.findbyCredentials(req.body.email,req.body.password)
const token = await user.generatejwt()
if(!user)
{
return res.status(400).send('Unable to login')
}
res.status(200).send({user,token})
})
The text was updated successfully, but these errors were encountered: