inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Một trại huấn luyện phát triển toàn diện thực sự dành cho những người không chuyên ngành

Triển khai API Tạo, Tra cứu Sản phẩm

다른건 다되는데 typeerror 가 뜹니다..

403

작성자 없음

0 câu hỏi đã được viết

0

1.<pre>TypeError: Cannot read properties of undefined (reading &#39;create&#39;)

const express = require("express");
const cors = require("cors");
const { application } = require("express");
const app = express();
const port = 8080;
const models = require("./models");
app.use(express.json());
app.use(cors());
app.get("/products", (req, res) => {
  const query = req.query;
  console.log("QUERY:", query);
  res.send({
    products: [
      {
        id: 1,
        name: "농구공",
        price: 100000,
        seller: "조던",
        imgUrl: "images/products/basketball1.jpeg",
      },
      {
        id: 2,
        name: "축구공",
        price: 50000,
        seller: "메시",
        imgUrl: "images/products/soccerball1.jpg",
      },
      {
        id: 3,
        name: "키보드",
        price: 10000,
        seller: "그랩",
        imgUrl: "images/products/keyboard1.jpg",
      },
    ],
  });
});
app.post("/products", (req, res) => {
  const body = req.body;
  const { name, description, price, seller } = body;
  models.Product.create({
    name,
    description,
    price,
    seller,
  })
    .then((result) => {
      console.log("상품 생성 결과 : ", result);
      res.send({
        result,
      });
    })
    .catch((error) => {
      console.error(error);
      res.send("상품 업로드에 문제가 생겼습니다.");
    });
});

app.get("/products/:id/events/:eventId", (req, res) => {
  const params = req.params;
  const { id } = params;
  res.send();
});

app.listen(port, () => {
  console.log("그랩의 쇼핑몰 서버가 돌아가고 있습니다.");
  models.sequelize
    .sync()
    .then(() => {
      console.log("DB 연결 성공");
    })
    .catch((err) => {
      console.error(err);
      console.log("DB 연결 에러 ㅠ ");
      process.exit();
    });
});

그 전까진 다 실행 잘되고 테이블도 잘 만들어졌는데 postman 에 send 를 누르면 이렇게 나옵니다

스크린샷, 2022-09-01 21-12-48.png

body 안에는 잘 들어가는데 create 에서 문제가 생긴거 같습니다. ㅠㅠ

tensorflow 머신러닝 배워볼래요? javascript HTML/CSS react-native nodejs react express

Câu trả lời 2

0

promotion

오래된 글이긴하나
동일한 오류 겪었는데 저와 같은 원인인지 중복체크 해보시면 좋을 것 같습니다.

  1. product.js 오류
    [models] > [product.js] > product 값이 대소문자가 틀리는 경우가 있었구요

  2. POSTMAN JSON 형식 오류
    POSTMAN 에서 JSON 형식에서 마지막 변수에 ,를 붙인다던가 "" 변수타입을 틀린다던가

0

grab

음 models쪽에 Product가 undefined여서 생기는 이슈 같은데요.

혹시 models 등록은 잘 되어있을까요?

[해결]그랩님 답변 주세요.

0

165

2

그랩님의 답변을 기다립니다/102강 전반적인 에러

0

144

2

[그랩님께]101강 안드로이드 에러들(Key prop)해결방법 궁금합니다.

0

126

2

[재질문][그랩님 답변 부탁드립니다]101강

0

143

2

[그랩님 답변 부탁드립니다]101강 Axios 에러와 502 Bad Gateway 질문

0

99

2

Ngrok 설치 후 forwarding Url 에러

0

134

2

[그랩님께,Ngrok 악성코드 인식 해결방법]질문 드립니다.

0

222

2

Ngrok 설치 후 forwarding Url로 연결 불가

0

138

1

그랩님,[꼭] 답변 부탁드립니다.

0

68

1

[꼭][[꼭] 그랩님, 답변 부탁드립니다], Failed to load resource: the server responded with a status of 404 (Not Found) 상품 상세 페이지 질문입니다.

0

155

1

6강/7강 수업

0

53

1

그랩님, 상품 상세 페이지 에러와 의문점 질문드립니다.

0

100

2

그랩님, 해결되지 않은 에러 메시지 [꼭] 답변 부탁 드립니다.

0

138

2

[재 질문]Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

89

1

Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

130

2

일반적인 css 꾸미기에서 width와 height의 값?

0

94

2

Windows에서의 업로드 후 홈화면 상품이미지 오류 해결방법

0

198

1

그랩마켓 웹화면 구현하기 -2 질문입니다.

0

121

1

react에 반영이 되지 않습니다.

0

243

1

터미널 npm install -g create-react-app 작성 후 오류

0

422

1

create-react-app my app 실행 시 에러

0

357

2

포스트맨 질문

0

100

1

<꼭 답변 부탁 드립니다>그랩선생님, [컴포넌트 사용하기] 강의에서 질문 있습니다.

0

261

2

그랩선생님, 질문 답변 부탁 드립니다.vscode에서 npm install -g create-react-app 입력 후 에러 입니다.

0

483

2