Error: Terminal SyntaxError - argument list is missing closing parenthesis

Encountering an issue while attempting to establish a connection with a Mongo DB database using the following code:

const mongoose = require('mongoose');

//Connect to mongodb
mongoose.connect('mongodb://localhost/testaroo');

mongoose.connection.once('open'.function(){
console.log('Connection has been made');                                           

}).on('error', function(error){
console.log('Connection Error:', error);
});

However, when trying to connect through Terminal

MG-MC-iMacs-iMac:~ MG-MC-TJUBA$ node mongodb/PingPongDB/connection.js

An error is displayed:

/Users/MG-MC-TJUBA/mongodb/PingPongDB/connection.js:6
mongoose.connection.once('open'.function(){
                                     ^

SyntaxError: missing ) after argument list
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3

The error message suggests a missing ')' that seems to be already present and necessary based on my analysis.

Answer №1

There is a syntax issue with your coding

mongoose.connect('mongodb://localhost/test', {
    useNewUrlParser: true,
    useUnifiedTopology: true
})
.then(() => console.log('Connected to database'))
.catch(error => console.error('Error connecting to database:', error));

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

Utilizing useEffect Hooks to Filter Local JSON Data in React Applications

For my engineering page, I have been developing a user display that allows data to be filtered by field and expertise. Fields can be filtered through a dropdown menu selection, while expertise can be filtered using an input field. My initial plan was to ...

When collapsing an accordion, Bootstrap radio buttons fail to properly select

I have attempted various methods to achieve the desired functionality of having the accordion content close and open accordingly when checking a radio button, while also having the button visually appear as 'checked'. For a more in-depth example, ...

The JavaScript function's if and else statements are being executed simultaneously

Upon loading the page, I am checking the value of a dropdown. Strangely, when I debug, it appears that the controller is executing both the if and else statements, which should not be happening. /* Here is my code: */ $(window).load(function() { ...

Is it normal for a Firebase listener to trigger twice when adding date to the database in React?

I've developed a basic chat application. Once the user submits a message, it is stored in the database along with their username. this.ref.child("/chat").update({username: this.state.username, message: this.state.chatMessage}); Subsequently, I ...

changing web pages into PDF format

I need to convert HTML to PDF on a Linux system and integrate this functionality into a web application. Can you suggest any tools that are capable of doing this? Are there any other tools I should consider for this task? So far, I have attempted the foll ...

Enhance your Next JS website's SEO with a combination of static pages, SSR pages, and client-side

In my project using Apollo GraphQL with Next JS, I have explored three different approaches to querying and rendering data. The first method involves Static Rendering by utilizing getStaticProps(), which looks like the following: export async function getS ...

Creating a custom hook in React to manage dynamic refs

Creating an app that heavily utilizes animations has posed a challenge for me, especially when dealing with dynamic refs and custom hooks. One of my custom hooks adds a click event listener, manages an animation, and returns a ref: const usePageChange = ( ...

Setting a default action for an Ext.Ajax.request error situation

In my application, I frequently make ajax requests using the Ext.Ajax.request method. Often, I find myself skipping error handling for failed requests due to time constraints or lack of interest in implementing fancy error handling. As a result, my code us ...

Can AngularJS Filters be used to convert a number into a string, but not the other way around?

After researching Angular JS filters, I discovered that the number filter is used to format a number as a string. However, there doesn't seem to be a built-in filter for converting a string to a number. In an attempt to solve this issue, here is so ...

Having trouble with an AJAX request to display a template in Flask

Imagine having two radio buttons labeled 1 and 2, along with some text at the bottom of a webpage. Initially, the text value is set to -1 and no radio buttons are selected. If one of the radio buttons is clicked, the text value should change to either 1 or ...

Having trouble displaying images using ejs.renderfile

I've been struggling to generate a PDF from an EJS file with the image rendering correctly. Here is my setup: My app.js code snippet: let express = require("express"); let app = express(); let ejs = require("ejs"); let pdf = require("html-pdf"); let ...

Stop the enter key from triggering button click events in Vue

I am trying to make my button only fire on click events, not when pressing enter, and it currently functions dynamically: <button class="btn btn-primary" type="button" v-on="{ click: isInProgress ? stop : start }"> My q ...

Prettier eliminates the need for parentheses in mathematical expressions

When working with mathematical expressions in React and attempting to slice an array based on those expressions, I encountered an issue with the Prettier extension. It automatically removes parentheses from the expressions, resulting in incorrect calculati ...

All submenus will be shown simultaneously

All sub menus are displayed at once when any button that triggers the event is clicked. For a live demonstration, click here: https://jsfiddle.net/saidmontiel/734szqLg/9/ I'm interested in having only one submenu appear at a time. I am aware that ...

Update the text content when clicked in React

For the onClick event, I am attempting to edit the entered text using the enableEdit function. My goal is to trigger the function when double-clicking on the entered text. Here is a snippet of my code: class App extends React.Component { const ...

Integrate your React Native application with a Node.js backend on your local machine

My attempt to establish a connection between my react native app and my node.js app on a Windows system has hit a roadblock. While I am able to receive responses from the node API using Postman, the response from the react native app is coming back as unde ...

What steps do I need to take to link my form with Ajax and successfully submit it?

Here is my HTML code: {% extends 'base.html' %} {% block content %} <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Create a Recipe ...

Is it acceptable to compare a boolean with a string?

In my code, I have a variable called isRefreshed which is initially declared like this: var isRefreshed = ''; Sometimes, in certain scenarios, isRefreshed can be assigned a boolean value, for example: isRefreshed = false; Now, there is an if ...

Retrieve the Typescript data type as a variable

I have the following components: type TestComponentProps = { title: string; } const TestComponent: React.FC<TestComponentProps> = ({ title, }) => { return <div>TestComponent: {title}</div>; }; type TestComponent2Props = { bod ...

Transferring Composite Data Structures from JavaScript to a WCF RESTful Service

Below are the code snippets: 1. The intricate object: [DataContract] public class NewUser { [DataMember(Name = "Email")] public string Email { get; set; } [DataMember(Name = "FirstName")] public string FirstName { get; set; } [DataMem ...