简体   繁体   English

nodemon_app 崩溃 - 在开始之前等待文件更改

[英]nodemon_app crashed - waiting for file changes before starting

1.This is my productController: 1.这是我的产品控制器:

const Product = require('../models/product')
//Create 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 show all produts in database.'

    })
}
  1. This is my package.json file这是我的 package.json 文件
{
    "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 my server.js file这是我的 server.js 文件
const app = require('./app');
const connectDatabase = require('./config/database')
const dotenv = require('dotenv');
//Setting up config files
dotenv.config({ path: 'backend/config/config.env' })
//Connecting to database
connectDatabase();
app.listen(process.env.PORT, () => {
    console.log(`Server started on PORT: ${process.env.PORT} in ${process.env.NODE_ENV} 
mode.`)
});
  1. This is 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;

This is my 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...

you should remove the colon from the newProduct function like so你应该像这样从 newProduct function 中删除冒号

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “ [nodemon]应用程序崩溃-等待文件更改,然后再开始...” - '[nodemon] app crashed - waiting for file changes before starting…' nodemon,应用程序崩溃,在启动前等待文件更改 - nodemon , app crashed , waiting for file changes before starting mondoDB 的 Nodemon 错误:“应用程序崩溃 - 启动前等待文件更改” - Nodemon error with mondoDB: “ app crashed - waiting for file changes before starting” nodemon 应用程序崩溃 - 在开始之前等待文件更改? - nodemon app crashed - waiting for file changes before starting? React js - nodemon:应用程序崩溃 - 在启动之前等待文件更改 - React js - nodemon: app crashed - waiting for file changes before starting nodejs:nodemon应用程序崩溃-在启动前等待文件更改 - nodejs : nodemon app crashed - waiting for file changes before starting nodemon 应用程序崩溃 - 在从服务器获得响应后开始错误之前等待文件更改 - nodemon app crashed - waiting for file changes before starting error after geting response from server 节点 js 错误:[nodemon] 应用程序崩溃 - 启动前等待文件更改 - Node js error: [nodemon] app crashed - waiting for file changes before starting nodemon 应用程序崩溃 - 在启动前等待文件更改。 有人可以解决这个问题吗 - nodemon app crashed - waiting for file changes before starting. Can someone sort this out please 当我运行 nodemon 服务器时,我收到错误消息“错误的身份验证失败。[nodemon] 应用程序崩溃 - 在开始之前等待文件更改......” - When I run nodemon server I get the error "bad auth Authentication failed. [nodemon] app crashed - waiting for file changes before starting..."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM