강의

멘토링

로드맵

Inflearn Community Q&A

moonjong938083's profile image
moonjong938083

asked

Creating Nodebird SNS with Vue

4-4. Sending Data to the Server

강의 듣는중 에러가 떠서 질문 드립니다 ㅜ

Written on

·

1.2K

0

이러한 에러가 뜨는데 어디서부터 무엇이 잘못된건지 햇갈리네요 ㅜ 왜 이런 에러가 뜨는 걸까요??

[nodemon] restarting due to changes...

[nodemon] starting `node app.js`

internal/modules/cjs/loader.js:883

  throw err;

  ^

Error: Cannot find module '/../config/config.json'

Require stack:

- C:\Users\com\vue강좌\라우터복습\ch4\back\models\index.js

- C:\Users\com\vue강좌\라우터복습\ch4\back\app.js

    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)

    at Function.Module._load (internal/modules/cjs/loader.js:725:27)

    at Module.require (internal/modules/cjs/loader.js:952:19)

    at require (internal/modules/cjs/helpers.js:88:18)

    at Object.<anonymous> (C:\Users\com\vue강좌\라우터복습\ch4\back\models\index.js:3:16)

    at Module._compile (internal/modules/cjs/loader.js:1063:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

    at Module.load (internal/modules/cjs/loader.js:928:32)

    at Module.require (internal/modules/cjs/loader.js:952:19) {

  code: 'MODULE_NOT_FOUND',

  requireStack: [

    'C:\\Users\\com\\vue강좌\\라우터복습\\ch4\\back\\models\\index.js',

    'C:\\Users\\com\\vue강좌\\라우터복습\\ch4\\back\\app.js'

  ]

}

[nodemon] app crashed - waiting for file changes before starting...

ssrvuexawsvuejsmysqlnodejs

Quiz

프론트엔드와 백엔드 서버를 분리하는 주된 이유가 무엇일까요?

단일 서버 성능 향상

확장이 용이하고 자원 관리가 효율적입니다.

모든 최신 프레임워크의 요구사항입니다.

서로 다른 언어를 사용할 수 있게 합니다.

Answer 5

0

moonjong938083님의 프로필 이미지
moonjong938083
Questioner

index.js 에 '../config/config.json

이부분 앞에 슬래쉬 하나가 더 들어 간거 같아서 제거하고 npm run dev를 해보니 이번엔 좀 다르게 뜨네요 ㅜㅜ

[nodemon] restarting due to changes...

[nodemon] starting `node app.js`

백앤드 서버 3085번 포트에서 작동중

(node:26792) UnhandledPromiseRejectionWarning: SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306

    at ConnectionManager.connect (C:\Users\com\vue강좌\라우터복습\ch4\back\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:116:17)

    at processTicksAndRejections (internal/process/task_queues.js:93:5)

    at async ConnectionManager._connect (C:\Users\com\vue강좌\라우터복습\ch4\back\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:318:24)

    at async C:\Users\com\vue강좌\라우터복습\ch4\back\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:250:32

    at async ConnectionManager.getConnection (C:\Users\com\vue강좌\라우터복습\ch4\back\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:280:7)      

    at async C:\Users\com\vue강좌\라우터복습\ch4\back\node_modules\sequelize\lib\sequelize.js:613:26

    at async MySQLQueryInterface.createTable (C:\Users\com\vue강좌\라우터복습\ch4\back\node_modules\sequelize\lib\dialects\abstract\query-interface.js:225:12)        

    at async Function.sync (C:\Users\com\vue강좌\라우터복습\ch4\back\node_modules\sequelize\lib\model.js:1300:5)

    at async Sequelize.sync (C:\Users\com\vue강좌\라우터복습\ch4\back\node_modules\sequelize\lib\sequelize.js:793:35)

(Use `node --trace-warnings ...` to show where the warning was created)

(node:26792) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

(node:26792) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

빨갛게 뜨지 않는거 보니 에러같은건 아닌거 같은데 ㅜ 백앤드 들어와서 힘드네요 ㅜ

0

moonjong938083님의 프로필 이미지
moonjong938083
Questioner

코드를 못올려 올려드립니다!

0

moonjong938083님의 프로필 이미지
moonjong938083
Questioner

app.js

const express = require('express');
const db = require('./models')
const app = express();

db.sequelize.sync();

app.use(express.json());
app.use(express.urlencoded({ extendedfalse }))

app.get('/', (reqres=> {
    res.send('안녕 시퀄라이즈')
})

app.post('/user'async (reqres=> {
    try {
        const newUser = await db.User.create({
            where: {
                emailreq.body.email,
                nicknamereq.body.nickname,
                passwordreq.body.password,
            }
        })
        res.status(201).json()
    } catch (err) {
        console.log(err)
        next(err)
    }
    
})

app.listen(3085, () => {
    console.log(`백앤드 서버 ${3085}번 포트에서 작동중`)
})

0

moonjong938083님의 프로필 이미지
moonjong938083
Questioner

user.js

module.exports = (sequelizeDataTypes=> {
  const User = sequelize.define('User', {
    email: {
      typeDataTypes.STRING(40), // 40자 이내
      allowNullfalse// 필수
      uniquetrue// 중복금지
    },
    nickname: {
      typeDataTypes.STRING(20),
      allowNullfalse,
    },
    password: {
      typeDataTypes.STRING(100),
      allowNullfalse,
    },
  }, {
    charset'utf8',
    collate'utf8_general_ci'// 한글 저장돼요
  });

  User.associate = (db=> {
    db.User.hasMany(db.Post);
    db.User.hasMany(db.Comment);
  };

  return User;
};

0

moonjong938083님의 프로필 이미지
moonjong938083
Questioner

index.js

const Sequelize = require('sequelize');
const env = process.env.NODE_ENV || 'development';
const config = require('/../config/config.json')[env];
const db = {};

const sequelize = new Sequelize(config.databaseconfig.usernameconfig.passwordconfig);

db.User = require('./user')(sequelizeSequelize)

Object.keys(db).forEach(modelName => {
  if (db[modelName].associate) {
    db[modelName].associate(db);
  }
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
zerocho님의 프로필 이미지
zerocho
Instructor

require('../config/config.json') 입니다.

moonjong938083님의 프로필 이미지
moonjong938083
Questioner

답변 감사합니다 강사님!!
고치고 npx sequelize db:create라고 쳤는데

Sequelize CLI [Node: 14.16.0, CLI: 6.2.0, ORM: 6.6.5]

Loaded configuration file "config\config.json".

Using environment "development".

ERROR: connect ECONNREFUSED 127.0.0.1:3306

이렇게 뜨는거는 어떤 이유일까요??ㅜ

zerocho님의 프로필 이미지
zerocho
Instructor

DB 서버를 실행 안 하신 겁니다. mysql 실행하세요.

moonjong938083님의 프로필 이미지
moonjong938083
Questioner

예 감사합니다 강사님 

어제 mysql 깔고 실행시켰는데 

Sequelize CLI [Node: 14.16.0, CLI: 6.2.0, ORM: 6.6.5]

Loaded configuration file "config\config.json".

Using environment "development".

ERROR: Access denied for user 'root'@'localhost' (using password: YES)

이러한 에러가 뜹니다 ㅜ 구글링 해보니 비번이 잘못 되서 그렇다고 하는데 mysql workbrench 하고 명령 프롬프터에서도 비번 치고 들어가졌는데 뭐가 문제인지 잘 모르겠습니다 ㅜ

moonjong938083님의 프로필 이미지
moonjong938083
Questioner

아 강사님 해결했습니다!!

config.json에서 비밀번호를 다르게 설정해놨었네요ㅜ
감사합니다!!^^

moonjong938083's profile image
moonjong938083

asked

Ask a question