The application monitored by nodemon has halted - awaiting modifications in files before restarting the process

1. My ProductController Implementation:

const Product = require('../models/product')
//Creating a new product => /ap1/v1/product/new
exports.newProduct = async(req, res, next) => {
    const product = await Product.create(req.body);

    res.status(201).json({
        success: true,
        product:
    })
}

exports.getProducts = (req, res, next) => {
    res.status(200).json({
        success: true,
        message: 'This route will display all products stored in the database.'

    })
}
  1. The content of my package.json file:
{
    "name": "shopit",
    "version": "1.0.0",
    "description": "e-commerce using MERN",
    "main": "server.js",
    "scripts": {
        "start": "node backend/server.js",
        "dev": "SET NODE_ENV=DEVELOPMENT& nodemon backend/server",
        "prod": "nodemon ./server.js localhost 8080: "

    },
    "author": "Floyd",
    "license": "ISC",
    "dependencies": {
        "dotenv": "^8.2.0",
        "express": "^4.17.1",
        "mongoose": "^5.11.13"
    },
    "devDependencies": {
        "nodemon": "^2.0.7"
    }
}
  1. This is the server.js setup:
const app = require('./app');
const connectDatabase = require('./config/database')
const dotenv = require('dotenv');
//Configuring environment variables
dotenv.config({ path: 'backend/config/config.env' })
//Connecting to the database
connectDatabase();
app.listen(process.env.PORT, () => {
    console.log(`Server running on PORT: ${process.env.PORT} in ${process.env.NODE_ENV} 
mode.`)
});
  1. The content of my routes file:
const express = require('express');
const router = express.Router();
const { getProducts, newProduct } = require('../controllers/productController');
router.route('/products').get(getProducts);
router.route('/product/new').post(newProduct);
module.exports = router;

The encountered error:

D:\PROGRAMMING\2077\SHOPIT\backend\controllers\productController.js:12
    })
    ^

SyntaxError: Unexpected token '}'
    at wrapSafe (internal/modules/cjs/loader.js:979:16)     
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)  
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)      
    at Object.<anonymous> (D:\PROGRAMMING\2077\SHOPIT\backend\routes\product.js:4:37)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
[nodemon] app crashed - waiting for file changes before starting...

Answer №1

To properly update the newProduct function, make sure to remove the colon in the code snippet below:

exports.newProduct = async (req, res, next) => {
  const product = await Product.create(req.body);
  res.status(201).json({
    success: true,
    product 
  });
};

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

AngularJS: Patience for an asynchronous request

I'm having trouble understanding the concept of promises in AngularJS. Here is a provider I have: var packingProvider = angular.module('packingProvider',[]); packingProvider.provider('packingProvider',function(){ ...

Could not locate module: Issue: Unable to resolve './Firebase'

I'm a beginner with React and I've been working on setting up Firebase in my React application. import firebase from 'firebase/compat/app'; import 'firebase/compat/auth'; import 'firebase/compat/firestore'; var fire ...

Issue: No build script found in npm5Problem:

To start testing with NPM 5, execute npm test command: "scripts": { "build": "babel src -d dist", "test": "npm run build; mocha --require 'babel-polyfill' --compilers js:babel-register './tests/**/*.spec.js'" }, An error occ ...

Filtering an array dynamically by utilizing an array of conditions

Can jQuery-QueryBuilder be used to filter an array? This amazing plugin generates a unique array of conditions: condition:"AND" rules: { field:"name" id:"name" input:"select" operator:"equal" type:"string" value:"Albert" } I have ...

Struggling to insert a JavaScript variable into a MySQL database table using PHP and AJAX

As a newcomer to these technologies, I've been struggling all day with what I expected to be a simple task. My goal is to pass a parameter from a JS function to my PHP code using AJAX and then insert that parameter into my database. Here's the J ...

JavaScript: Struggles with utilizing a function as an argument and later executing it inside a nested function

I've been struggling with defining a new function, and I need help resolving it. Here's an example that I was initially referencing: Pass arguments into ajax onreadystatechange callback? I wasn't able to find the solution through research, ...

What is the reason behind the delayed mutation of the state when invoking the setState method in React?

Currently diving into the Forms section within the documentation of ReactJS. Just implemented this code snippet to showcase the use of onChange (JSBIN). var React= require('react'); var ControlledForm= React.createClass({ getInitialState: f ...

What is the best way to convert an Angular object into a string using a for-loop and display it using $sce in AngularJS?

Currently, I am rendering a block of HTML and directives using $sce.trustAsHtml. To achieve this, I utilized a directive called compile-template which enables the use of ng-directives like ng-click and ng-disabled. While it is possible for me to pass sta ...

The canvas's document.getElementById function is unable to find any matching element,

Hello everyone, I am currently diving into the world of javascript and trying to expand my knowledge. However, I have encountered a problem that has me stumped, and I could really use some assistance. While exploring, I came across this page: http://www.w ...

Is there a way to access the rear camera on a mobile device using webcam.js?

Currently, I am utilizing webcam.js from the following link: https://github.com/jhuckaby/webcamjs. When accessing the website on mobile devices, the front camera tends to open by default. My objective is to switch this default setting to access the rear ...

Tips for animating a nested array using jQuery

I have a border that is 9x9 with lines, columns, and squares, similar to a Sudoku border. I want to animate it, but I encountered some issues when trying to run multiple animations simultaneously. To solve this problem, I decided to animate one array of el ...

ng-bind-html is having trouble parsing the HTML correctly and binding it

Here is the code for my controller: myApp.controller('actionEditController', ['$scope', '$stateParams', '$sce',function ($scope, $stateParams, $sce) { $scope.table="<p>OOPSY</p>"; $sc ...

How can I determine when a WebSocket connection is closed after a user exits the browser?

Incorporating HTML5 websocket and nodejs in my project has allowed me to develop a basic chat function. Thus far, everything is functioning as expected. However, I am faced with the challenge of determining how to identify if connected users have lost th ...

Manipulating video volume using JavaScript injection

My web page includes a video, and I have successfully used JavaScript injection to control the play/pause functionality. Now, I am looking to also adjust the volume based on percentage. How can I create a function that decreases or increases the volume acc ...

Struggling to bring in node packages into React components

I'm currently exploring a local setup with drf-react. As someone new to react and javascript in general, I'm facing a challenge with importing axios or other node modules into my react components. It seems like I can only access the modules that ...

Updating package.json dependencies while linking from globally installed packages - a quick guide

I streamline my development projects by globally installing all necessary npm packages with the command: npm -g install [package] Subsequently, I create symbolic links for the required dependencies on a project-by-project basis using: npm link [package] ...

Trouble with executing AJAX for API call

My current project is built on CI3 and I have created an API that belongs to a different domain than the application itself. $.ajax({ url: "http://www.example.com/restapi/index.php/api/user", type: "GET", data: {"user_id": user_id} ...

String casting for large JavaScript integers may require rounding to function properly

When trying to pass a large integer to a function from an onclick event in HTML, I always encounter issues with rounding. Despite using bigInt libraries, I still struggle to pass the full number accurately and would prefer a simple string casting method. ...

What could be causing the browser to become unresponsive when making several AJAX requests to the same ASP.NET MVC action at once?

The other day, I posed this query: Why is $.getJSON() causing the browser to block? I initiated six jQuery async ajax requests simultaneously on the same controller action. Each request takes around 10 seconds to complete. Upon tracking and logging re ...

Is it possible to share data from one controller in a JS file to another JS file? (using AngularJS)

I need to create a table in JavaScript. In one of my JS files, I have a controller with JSON data containing properties like width, height, color, etc. In another JS file, I am building the actual table structure. Here is an example of my AngularJS file: ...