Quantcast
Channel: Active questions tagged mongodb-atlas - Stack Overflow
Viewing all articles
Browse latest Browse all 315

Type error cannot add property next, object is not extensible

$
0
0

I am getting the error:home/maxinejones/development/level-6/Recipe-Logger/node_modules/express/lib/router/index.js:161 req.next = next;^

TypeError: Cannot add property next, object is not extensibleat Function.handle (/home/maxinejones/development/level-6/Recipe-Logger/node_modules/express/lib/router/index.js:161:12)at Function.handle (/home/maxinejones/development/level-6/Recipe-Logger/node_modules/express/lib/application.js:181:10)at app (/home/maxinejones/development/level-6/Recipe-Logger/node_modules/express/lib/express.js:39:9)at Object. (/home/maxinejones/development/level-6/Recipe-Logger/server.js:11:1)While I am trying to set up atlas, I am unsure what is causing the error, I know the code works because it works on my local server, however, when i try to use the mongodb atlas connection string, It doesn't work.

const express = require('express')const mongoose = require('mongoose')const morgan = require('morgan')const app = express()const bodyParser = require('body-parser')const path = require("path")app.use(morgan('dev'))require('dotenv').config()const { expressjwt: jwt } = require("express-jwt")app.use(bodyParser.json())`mongodb+srv://mjones89:carmax23@cluster0.mdy4n.mongodb.net/<dbname>?retryWrites=true&w=majority`mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true });app.use('/auth', require('./routes/authRouter'))app.use("/api", jwt( {secret: process.env.SECRET, algorithms: ['HS256']}))app.use('/api/recipe/', require('./routes/recipeRoutes'))app.use('/api/comments/', require('./routes/commentRouter'))app.use('/api/ingredients/', require('./routes/ingredRouter'))app.use((err,req,res,next)=>{    console.log(err)    if(err.name ==='UnauthorizedError'){        res.status(err.status)    }    return res.send({message:err.message})})// ... other app.use middlewareapp.use(express.static(path.join(__dirname, "client", "dist")))// ...// Right before your app.listen(), add this:app.get("*", (req, res) => {    res.sendFile(path.join(__dirname, "client", "dist", "index.html"));});app.listen(8000, ()=>{    console.log('hello ')})

Viewing all articles
Browse latest Browse all 315

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>