Server crashing as nodemon encounters mongoose issue

Currently, I am in the process of learning Node JS, Mongodb, and Express JS. My goal was to create a database using Mongodb Compass and store some data within it. However, every time I attempt to run my code, my nodemon server crashes after a few minutes of starting.

Below are the main files containing the code:

app.js -

(code snippet here...)

user.js -

(code snippet here...)

index.js -

(code snippet here...)

The purpose behind writing this code was to set up a database for learning and practice. When I run the code on localhost:3000 with the "npx nodemon" command, everything works fine until reaching the index file of the website. However, upon attempting to access the /create route via the URL "localhost:3000/create," the server hangs for a few seconds before crashing. The error message displayed in my terminal reads:

MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 (attempted solution instructions...) Node.js v20.5.1 [nodemon] app crashed - waiting for file changes before starting...

I also tried accessing Mongodb Compass to investigate the issue further. Upon trying to connect to the database, I encountered the following error - connect ECONNREFUSED 127.0.0.1:27017

If anyone could assist me by identifying the cause of this problem and providing a solution, I would greatly appreciate it.

Answer №1

When you see the ECONNREFUSED 127.0.0.1:27017 error, it means that there is no program actively listening on the specified port and IP address.

It seems like you are attempting to establish a connection with a MongoDB database. Ensure that MongoDB is properly installed and operational on port 27017.

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

Incorporating VueJS with a sleek material design aesthetic

Currently, I am in the process of developing a web application using VueJs and am in need of a CSS framework to aid in designing without starting from scratch! After some research, I came across material-design-lite (www.getmdl.io) but unfortunately faced ...

What is the best method for sending a PHP variable to an AJAX request?

I am working with three files - my main PHP file, functions.php, and my JS file. My challenge is to pass a PHP variable to JavaScript. Below is a snippet from my MAIN PHP FILE: function ccss_show_tag_recipes() { //PHP code here } Next, here's t ...

ES6: Using DataURI to provide input results in undefined output

In my current project, I am facing a challenge. I am attempting to pass image dataURI as an input from a url link to the image. To achieve this task, I know that I have to utilize canvas and convert it from there. However, since this process involves an &a ...

What steps must be taken to establish a universal connection to MongoDB that can be shared across multiple files?

Currently, I have my main server file named index.js: const express = require('express') const app = express() const route = require('./route') app.use('/main', route) app.listen(3000) Additionally, there is the route.js f ...

What is the best way to retrieve strings from an asynchronous POST request?

I am currently working on implementing a signup function in my Angular app using a controller and a factory. However, I am facing an issue where the strings (associated with success or failure) are not being returned from the factory to the controller as e ...

Ways to selectively implement the callback of setState using hooks in specific locations, rather than applying it universally

There are times when I need to set a state and perform an action afterwards, but other times not! How can I achieve this using hooks? Sometimes, I want to call a function or do something after setting the state: this.setState({inputValue:'someValue& ...

Adjust date by one day using the Datetimepicker tool

I have been attempting to adjust the date of my input by one day either forward or backwards, but I seem to be stuck and not making any progress. Take a look at my code: function function backDay() { var date = $('input#datetimepicker').va ...

Divide data into an HTML table and merge it with header information

My HTML form contains an interactive HTML table where users can add/delete rows. I am sending this data to a Google Sheet and need to store the row information with corresponding header details. Each time a user submits the form, a new row is added to the ...

The error message "email() is not a valid function when using the onclick attribute

Can anyone lend a hand? I feel like I must be overlooking something really obvious. I'm having trouble calling my function to execute my ajax call. Any assistance would be greatly appreciated. Thank you! Here is an excerpt of the HTML code: $(docu ...

MongoError: Unknown term '$last' detected ("build version": "5.0.4")

While attempting to aggregate the data I am utilizing MongoDB with version "5.0.4" { $project: { _id: 1, feeling: 1, updated_date: 1, ...

Is your YQL JSON script failing to provide the expected output?

Here is a script that I have copied almost directly from this. Why is it that the code below does not seem to return anything? ajax.html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html dir="lt ...

What causes offsetHeight to be less than clientHeight?

INFORMATION: clientHeight: Retrieves the height of an element, taking into account padding offsetHeight: Obtains the height of an element, considering padding, border, and scrollbar Analyzing the Data: The value returned by offsetHeight is expected to ...

Guide to scraping a website using node.js, ASP, and AJAX

I am currently facing an issue where I need to perform web scraping on this specific webpage form. This webpage is dedicated to vehicle technical reviews, and you can try inputting the car license CDSR70 for testing purposes. As mentioned earlier, I am u ...

Incorporating a division using the data() method

Currently, I am in the process of generating a list of flash SWFs. The data for this list is retrieved through an ajax call, which returns a JSON object. To populate the rows with data, I utilize my makeAppRow function. makeAppRow = function(myData) { ...

Methods for showing Internet Explorer not supported in Angular without needing to import polyfills

Due to the deprecation of IE in Angular 12, I need to inform users to switch to a supported browser by displaying a static warning on my page. To achieve this, I have implemented a simple snippet in the index.html file that appends a CSS class to the body ...

Align component within material-ui grid

Looking to center align the same cards but not just the grid component, I need the content itself to be equally distant from the borders and each other. I've searched and tried different solutions without luck. https://i.stack.imgur.com/aZj7H.png htt ...

What could be causing the async request with await to not properly wait for the response data?

I'm having trouble with the await function in my code, can anyone provide assistance? I've followed tutorials and copied the code exactly as shown but it still doesn't work. The CardsID array needs to be filled before I call console.log(Card ...

Start the Vue component only after ensuring that the element has been fully loaded

I have created a small vue.js component in JavaScript. Is there an elegant way to instantiate the vue component only when the element is loaded? The problem I am facing is that I'm receiving warnings in other HTML files where the element does not ex ...

The React application is experiencing difficulty in rendering SVG images exclusively on Windows operating systems

My react app runs smoothly on OSX, but encounters issues on Windows due to SVG files: Module parse failed: Unexpected token (2:0) You may need an appropriate loader to handle this file type. <svg xmlns="http://www.w3.org/2000/svg" viewBox="..."> I ...

Using the array.prototype.map method on props in React.js results in an array that is devoid

Recently, I've started exploring the world of React and encountered a problem while attempting to convert the value of props into a JSX element using array.prototype.map(). You can learn more about this method at this link. Here is a snippet of a Rea ...