Encountering an issue with MongoDB Atlas where properties of undefined cannot be read

Hey there, I'm diving into the world of MERN Stack and working on a booking application. Currently, I'm leveraging MongoDB Atlas for my database setup and following a tutorial on YouTube to grasp the concepts.

My current hurdle is connecting my index.js file to the .env file. I've input the connection string from MongoDB Atlas, but unfortunately, I'm encountering the following error:

TypeError: Cannot read properties of undefined (reading 'MONGO_URL') at Object. (C:\Users\Rashmika Satish\airbnbclone\api\index.js:20:29)
at Module._compile (node:internal/modules/cjs/loader:1254:14) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47

Here are the relevant files:

index.js file:

const express= require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const bcrypt=require('bcryptjs');
const User=require('./models/User.js');
require('dotenv').config();

const app=express();

const bcryptSalt=bcrypt.genSalt(10);

app.use(express.json());
app.use(cors({ 
      credentials:true,
      origin:'http://localhost:5173',
}))


console.log(process.env)
mongoose.connect(process.ev.MONGO_URL);

app.get('/test', (req,res)=> {
res.json('test ok');
});

app.post('/register', (req,res)=>{
    const {name,email,password}=req.body;
res.json({name,email,password});


   
    
    
});


app.listen(4000);

This is the .env file

MONGO_URL=mongodb+srv://*********:<password>@cluster0.1isyt6d.mongodb.net/?retryWrites=true&w=majority

(I've intentionally hidden the username and password for security purposes)

Answer №1

modification:

switch up:

from:

mongoose.connect(process.ev.MONGO_URL);

to:

mongoose.connect(process.env.MONGO_URL);

Answer №2

Line 20 appears to have a syntax error, specifically in process.ev.MONGO_URL, it should be process.env.MONGO_URL.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Knex is requesting the installation of sqlite3, but I am actually utilizing a MySQL database

While attempting to execute a query on my local MySQL database using knex, I encountered an issue where it prompted me to install the SQLite3 driver, even though my database is MySQL. To troubleshoot, I installed the SQLite3 driver to see if it would reso ...

Retrieve JSON data by making a POST request to a website's API

Can you help me retrieve Json data from a website API using JavaScript? I'm trying to fetch quotes from the following website: for my quotes generator page. While I have some understanding of making GET requests, it seems that this API requires POST ...

What could be causing the malfunction in my 'sort' function? I have thoroughly checked for errors but I am unable to locate any

Exploring the world of JavaScript objects to enhance my understanding of functions and object manipulation. I have created a program that constructs an Array of Objects, each representing a person's 'firstName', 'middleName', and & ...

Respond to onClientClick based on the button choice made by the user

In my code, there is an OnClientClick event set up like this: OnClientClick="return getErrors();". This function contains the following body: function getErrors() { var errorString = "some errors"; return $('<div id="dialog-message" title= ...

Develop a custom dropdown menu using JavaScript

I've been working on creating a dropdown menu that appears after selecting an option from another dropdown menu. Here's the HTML code I'm using: <br> <select id ="select-container" onchange="addSelect('select-container') ...

What could be causing Jquery to not function properly in an Angular controller?

Can someone please help me understand why my code is not working in JSFiddle? Any assistance would be appreciated! UPDATE: I have to admit, the negative feedback is disheartening. I may not know everything, but asking questions is how we learn. What' ...

Issue with Lazy Loading in Angular 4 Universal

I recently created a new Angular CLI project to delve into server-side rendering with Angular Universal. Everything was set up and running smoothly, until I decided to implement lazy-loading for a module named 'lazy'. After implementing lazy-lo ...

Navigate using React to a different HTML page based on certain conditions

After calling the fetch function, I am able to retrieve the correct token from the backend application. However, every time in this program, even if an incorrect token is retrieved, the program still navigates to StudentLobby (this should only happen when ...

The npm outdated command seems to ignore the caret notation specified in the package.json file

When looking at a package.json file that contains the following: "devDependencies": { "grunt": "^0.4.5", "grunt-concurrent": "^1.0.0", "grunt-contrib-jshint": "^0.10.0", "grunt-contrib-watch": "^0.6.1", "grunt-dev-update": "^1.1.0", ...

What is the process for removing a range of keys from indexeddb?

I need help deleting keys that start with tracklist/RANDOM_STRING and 'songBook/RANDOM_String'. I attempted to do this using IDBKeyRange but I am struggling to understand how it works. The documentation I referred to was somewhat confusing: Mdn ...

Using jQuery to create a flawless animation

I am currently working on an animation project, and I have shared my progress on jsfiddle. Below is the code snippet I have utilized: /* JavaScript: */ var app = function () { var self = this; var allBoxes = $('.box&apos ...

A guide on incorporating a React custom package within an Angular directive

Hey there, I have an Angular v1.x application and a React custom package. I'm looking to integrate the React custom package into my Angular directive, so that it can display a React component. Here's some code snippet: Angul ...

Determine the number of distinct elements in fields using MongoDB aggregation

After executing my query, I received documents in the following format: { _id: '48nmqsyxmswpkkded2ac_331fabf34fcd3935', actions: { sales: { pixel: [Object] } }, date: Sun Jul 27 2014 00:00:00 GMT-0400 (EDT), client: '48nmqsyxmswpkkded ...

Transferring a JavaScript variable to a PHP file through jQuery's Ajax functionality

I'm having trouble figuring out how to pass a JavaScript variable to a PHP script using AJAX. This is my first attempt at using AJAX and I seem to be missing something. Here's the code snippet: function selectCategory(value) { $.ajax({ ...

The submission of the form is prevented upon updating the inner HTML

I am in the process of creating a website that will incorporate search, add, update, and delete functionalities all on a single webpage without any modals. The main focus of this webpage is facility maintenance. Adding facilities works smoothly; however, i ...

Is it possible to disable the "super must be called before accessing this keyword" rule in babelify?

My current setup involves using babelify 7.2.0 with Gulp, but I've encountered an error when working with the following code snippet: class One {} class Two extends One { constructor() { this.name = 'John'; } } The issue at hand i ...

Tips for deleting a button from a DataTable file upload feature

I currently have Datatable set up to upload images using the code snippet below: { label: "Images:", name: "files[].id", type: "uploadMany", display: function ( fileId, counter ) { re ...

Angular 2 event emitter falling behind schedule

I am currently utilizing Angular 2 beta 6. The custom event I created is not being captured import {Component, OnInit, EventEmitter} from 'angular2/core'; import {NgForm} from 'angular2/common'; import {Output} from "angular2/core" ...

Exploring the capabilities of useRef in executing a function on a dynamically created element within a React/Remix/Prisma environment

I've been trying to implement multiple useRef and useEffect instructions, but I'm facing difficulties in getting them to work together in this scenario. The code structure involves: Remix/React, fetching data from a database, displaying the data ...

Utilizing the LinkedIn API: Posting a network update using a variable value

Currently, I have a string variable and I am looking to post the value stored in this variable as a network update on LinkedIn. Could someone please provide guidance on how I can modify the code below to make this functionality possible? updateURL = "/pe ...