inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

묻고 답해요

176만명의 커뮤니티!! 함께 토론해봐요.

[ODM-MongoDB접속] post요청 후 몽고DB에서 조회가 안됩니다.

해결됨

[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스

postman에서 post요청 후 get으로 확인했을 때 잘 받아와집니다. MongoDB Compass에 localhost :27017로 연결해서 refresh해도 mydocker DB가 조회가 안됩니다. docker - mongodb가 연결이 잘 안된건지 어렵습니다.. 어떻게 확인할 수 있을까요? import express from 'express' import { checkValidationPhone, getToken, sendTokenToSMS } from './phone.js'; import swaggerUi from 'swagger-ui-express' import swaggerJSDoc from 'swagger-jsdoc' import { options } from './swagger/config.js' import cors from 'cors' import { checkValidationEmail, getWelcomeTemplate, sendWelcomeTemplateToEmail } from './email.js'; import mongoose from 'mongoose' import { Board } from './models/board.model.js' const app = express() app.use(cors()) app.use(express.json()); app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerJSDoc(options))); app.get('/boards', async (req, res) => { // const result = [ // { // number: 1, // writer: '철수', // title: '제목입니다~~~', // contents: '내용이에요@@@', // }, // { // number: 2, // writer: '영희', // title: '영희 제목입니다~~~', // contents: '영희 내용이에요@@@', // }, // { // number: 3, // writer: '훈이', // title: '훈이 제목입니다~~~', // contents: '훈이 내용이에요@@@' // }, // ]; const result = await Board.find() //DB접속해서 가져오는 내용 위랑동일 res.send(result) }) app.post('/boards', async (req, res) => { console.log(req.body); // 1. 데이터를 등록하는 로직 => DB에 접속해서 데이터 저장하기 const board = new Board({ writer: req.body.writer, title: req.body.title, contents: req.body.contents, }); await board.save(); //원래는 SQL문법을 써야하지만 mongoose가 자동으로 변환해줌.(ORM, ODM) // 2. 저장 결과 응답 주기 res.send("게시물 등록에 성공하였습니다."); }); app.post('/tokens/phone', (req, res) => { const myphone = req.body.myphone; const isValid = checkValidationPhone(myphone); if (isValid) { const mytoken = getToken(); sendTokenToSMS(myphone, mytoken); res.send('인증완료!!!'); } }); app.post("/users", (req, res) => { const user = req.body.myuser const isValid = checkValidationEmail(user.email) if(isValid){ const mytemplate = getWelcomeTemplate(user) sendWelcomeTemplateToEmail(user.email, mytemplate) res.send("가입완료!") } }) //몽고DB 접속 mongoose.connect("mongodb://my-database:27017/mydocker") // localhost로 접속하게되면 express 도커안에서의 localhost이기때문에 dockercompose로 묶인 my-database-1 컴퓨터로 들어가야함. // 단, dockercompose로 묶어뒀기 때문에 이름만 입력해서 진입가능(네임리졸루션). // Backend API 서버 오픈 app.listen(3000, () => console.log(`exemple app listening on port ${3000}`))

  • javascript
  • node.js
  • express
  • docker
  • tdd
  • rest-api
  • nestjs
치카치카 댓글 1 좋아요 0 조회수 849

라우터 클래스 질문입니다

미해결

테스트주도개발(TDD)로 만드는 NodeJS API 서버

var user = require("./api/user"); app.use("/user", user); app.listen(3000, function () { console.log("Example app listening on port 3000"); }); module.exports = app; app.use("/user", user) 이렇게 하면 ./api/user/index.js파일에서 export한 router객체를 자동으로 참조하게 되는건가요? app.use("/user", router) 라고 해야 이해가 될거 같은데...express 문법을 몰라서 질문 올렸습니다

  • node.js
  • express
  • tdd
  • rest-api
가보자!! 댓글 1 좋아요 0 조회수 490

isLargeRow에 관한 질문입니다.

미해결

따라하며 배우는 리액트 A-Z[19버전 반영]

강의 열심히 듣고 있습니다. Row.js에서 사용하고 있는 isLargeRow에 관해 질문드립니다. isLargeRow는 부모 컴포넌트에서 boolean값을 설정하지 않고 단지 문자열로 props로 보내지는데 Rows.js에서는 true 값을 가지게 되는게 잘 이해가 안가네요 props로 문자열을 내려주면 자식 컴포넌트에서는 그 문자열이 내려오면 true로 없으면 false로 인식을 하는건가요? 바쁘시겠지만 답변 부탁 드리겠습니다.

  • react
  • redux
  • tdd
  • typescript
  • next.js
kium 댓글 1 좋아요 0 조회수 447

API 테스트로 전환하기

미해결

실전! 스프링부트 상품-주문 API 개발로 알아보는 TDD

해당 영상 내에서 굳이 var 타입을 사용하신 이유를 알 수 있을까요?

  • tdd
  • spring-boot
  • pojo
  • api
enble_777 댓글 1 좋아요 0 조회수 1066

몽고디비 접속 문제

해결됨

[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스

노션에 써있는걸로 sudo systemctl start mongod 실행하면 실행이 안되서 공식문서에서 찾아보니 sudo service mongod start 를 입력하면 starting database mongod 라고 뜬 후 fail이 뜹니다.... localhost:27017 로 접속을 하면 잘 뜨긴 하는데 해결 방법이 없을까요 ??

  • javascript
  • node.js
  • express
  • tdd
  • rest-api
  • nestjs
  • mongod
  • mongodb
cgc 댓글 1 좋아요 0 조회수 633

도커내부 접속 안됨

해결됨

[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스

docker run 이미지ID 하고 새로운 터미널 열어서 docker ps 로 containerID 확인 후 docker exec -it 명령어 사용해서 도커 내부로 들어가려고 하면 OCI runtime exec failed: exec failed: unable to start container process: exec: "C:/Program Files/Git/usr/bin/bash": stat C:/Program Files/Git/usr/bin/bash: no such file or directory: unknown 이런식으로 오류가 뜹니다 왜 그런건가요?? 해결 방법 알려주세요!

  • javascript
  • node.js
  • express
  • docker
  • tdd
  • rest-api
  • nestjs
cgc 댓글 1 좋아요 1 조회수 1573

N:M tag 부분 구현 중 findOne 조회 부분 에러

해결됨

[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스

products.service.ts에서 create 부근에 tag를 저장 하기 전 tag를 미리 조회하는 부분을 구현 중인데 findOne에서 {name: tagname} 을 구현하려고 할 때 다음과 같은 에러가 발생합니다. save에서는 에러가 발생하지 않는데 findOne 조회 부분만 에러가 발생하네요 관련된 코드 같이 보내드립니다. createProduct.input.ts import { InputType, Field, Int } from '@nestjs/graphql'; import { Min } from 'class-validator'; import { ProductSaleslocationInput } from 'src/apis/productsSaleslocation/entities/dto/productSaleslocation.input'; @InputType() export class CreateProductInput { @Field(() => String) name: string; @Field(() => String) description: string; @Min(0) @Field(() => Int) price: number; @Field(() => ProductSaleslocationInput) productSaleslocation: ProductSaleslocationInput; @Field(() => String) productCategotyId: string; @Field(() => [String]) productTags: string[]; } products.entity.ts import { Field, Int, ObjectType } from '@nestjs/graphql'; import { ProductCategory } from 'src/apis/productsCategory/entities/productsCategory.entity'; import { ProductTag } from 'src/apis/productsTags/productTags.entity'; import { User } from 'src/apis/users/users.entity'; import { Column, DeleteDateColumn, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToOne, PrimaryGeneratedColumn, } from 'typeorm'; import { ProductSaleslocation } from '../../productsSaleslocation/entities/productsSaleslocation.entity'; @Entity() @ObjectType() export class Product { @PrimaryGeneratedColumn('uuid') @Field(() => String) id: string; @Field(() => String) @Column() name: string; @Field(() => String) @Column() description: string; @Field(() => Int) @Column() price: number; @Field(() => Boolean) @Column({ default: false }) isSoldout: boolean; @DeleteDateColumn() deletedAt: Date; @Field(() => ProductSaleslocation) @JoinColumn() @OneToOne(() => ProductSaleslocation) productSaleslocation: ProductSaleslocation; @Field(() => ProductCategory) @ManyToOne(() => ProductCategory) productCategory: ProductCategory; @Field(() => User) @ManyToOne(() => User) user: User; @JoinTable() @ManyToMany(() => ProductTag, (productTags) => productTags.products) @Field(() => [ProductTag]) productTags: ProductTag[]; } productTags.entity.ts import { Field, ObjectType } from '@nestjs/graphql'; import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm'; import { Product } from '../products/entities/products.entity'; @Entity() @ObjectType() export class ProductTag { @Field(() => String) @PrimaryGeneratedColumn('uuid') id: string; @Column() @Field(() => String) name: string; @Field(() => [Product]) @ManyToMany(() => Product, (products) => products.productTags) products: Product[]; } products.service.ts import { Product } from './entities/products.entity'; import { Injectable, UnprocessableEntityException } from '@nestjs/common'; import { Repository } from 'typeorm'; import { InjectRepository } from '@nestjs/typeorm'; import { ProductSaleslocation } from '../productsSaleslocation/entities/productsSaleslocation.entity'; import { ProductTag } from '../productsTags/productTags.entity'; @Injectable() export class ProductService { constructor( @InjectRepository(Product) private readonly productRepository: Repository<Product>, @InjectRepository(ProductSaleslocation) private readonly productSaleslocationRepository: Repository<ProductSaleslocation>, @InjectRepository(ProductTag) private readonly productTagRepository: Repository<ProductTag>, ) {} async findAll() { return await this.productRepository.find({ relations: ['productSaleslocation', 'productCategory', 'productTags'], }); } async findOne({ productId }) { return await this.productRepository.findOne({ where: { id: productId }, relations: ['productSaleslocation', 'productCategory', 'productTags'], }); } async create({ createProductInput }) { // 1. 상품만 등록하는 경우 // const result = await this.productRepository.save({ // ...createProductInput, // // 하나 하나 직접 나열하는 방식 // // name: createProductInput.name, // // description: createProductInput.description, // // price: createProductInput.price, // }); // 2. 상품과 상품거래 위치 같이 등록 const { productSaleslocation, productCategotyId, productTag, ...product } = createProductInput; const result = await this.productSaleslocationRepository.save({ ...productSaleslocation, }); // productTag // ["#electronics, #computer"] const result2 = []; // [{name: ..., id: ...}] for (let i = 0; i < productTags.length; i++) { const tagName = productTags[i].replace('#', ''); // check the tags that has already registered const checkTag = await this.productTagRepository.findOne({ name: tagName, }); // if the tags has been existed if (checkTag) { result2.push(checkTag); // if the tags hasn't been existed } else { const newTag = await this.productTagRepository.save({ name: tagName }); result2.push(newTag); } } const result3 = await this.productRepository.save({ ...product, productSaleslocation: result, // result 통째로 넣기 vs id만 넣기 productCategory: { id: productCategotyId }, productTags: result2, }); return result3; } async update({ productId, updateProductInput }) { const myProduct = await this.productRepository.findOne({ where: { id: productId }, }); const newProduct = { ...myProduct, id: productId, ...updateProductInput, }; return await this.productRepository.save(newProduct); } async checkSoldOut({ productId }) { const product = await this.productRepository.findOne({ where: { id: productId }, }); if (product.isSoldout) { throw new UnprocessableEntityException('Sold out'); } // if(product.isSoldout) { // throw new HttpException('이미 판매 완료 된 상품입니다.', HttpStatus.UNPROCESSABLE_ENTITY) // } } async delete({ productId }) { // 1. 실제 삭제 // const result = await this.productRepository.delete({ id: productId }); // return result.affected ? true : false // 2. 소프트 삭제(직접 구현) - isDeleted // this.productRepository.update({ id: productId }, { isDeleted: true }); // 3. 소프트 삭제(직접 구현) - deletedAt // this.productRepository.update({ id: productId }, { deletedAt: new Date() }); // 4. 소프트 삭제(TypeORM 제공) - softRemove - id로만 삭제 가능 // this.productRepository.softRemove({ id: productId }); // 4 . 소프트 삭제(TypeORM 제공) - softDelete const result = await this.productRepository.softDelete({ id: productId }); return result.affected ? true : false; } } 내용 확인 부탁드립니다.

  • javascript
  • node.js
  • express
  • docker
  • tdd
  • rest-api
  • nestjs
유상우 댓글 2 좋아요 0 조회수 558

안녕하세요 질문있습니다!

해결됨

[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스

@ObjectType이랑 @EntryType이랑 같이 사용을 할수는 없는건가요?? dto와 entry가 다른부분이 없어서 같이 쓰는게 낫겠다싶어서 시도하려니 안되네요 확실히 역할을 나눠야하는건가요??

  • javascript
  • node.js
  • express
  • docker
  • tdd
  • rest-api
  • nestjs
gogo 댓글 1 좋아요 1 조회수 400

폴더 속 폴더에 있는 소스 배포

미해결

따라하며 배우는 리액트 A-Z[19버전 반영]

강사님 제가 넷플릭스 소스를 [git아이디/Repositories폴더/하위a폴더/하위b폴더] b폴더에 저장을 했다면 homepage경로와 base경로를 어떻게 설정해야하나요? 혹시 배포를 할땐 Repositories 폴더에 있는 소스들만 배포가 가능한건가요?

  • react
  • redux
  • tdd
  • typescript
  • next.js
뽀개즈아 댓글 1 좋아요 0 조회수 534

코드 스타일에 대해서 질문드립니다.

미해결

실전! 스프링부트 상품-주문 API 개발로 알아보는 TDD

변수들에 final 키워드를 붙이시는 이유 class를 만들때 접근지정자 public 을 지우시는 이유 메서드를 static 으로 생성하는 이유 위의 점들이 궁금합니다.

  • tdd
  • spring-boot
  • pojo
  • api
임요환 댓글 1 좋아요 2 조회수 1188

슈퍼 테스트2 강의 질문입니다

미해결

테스트주도개발(TDD)로 만드는 NodeJS API 서버

describe('GET /users는', () => { it('user리스트를 limit만큼 가져왔다', (done) => { request(app) .get('/users') .end((err, res) => { console.log(res.body) done() // 우리가 만든 API서버는 비동기로 동작한다. 그래서 비동기에 대한 처리로 콜백함수를 호출해야 한다?? }) }) }) 강사님께서 콜백함수 done()을 호출하는 부분에서 다음과 같이 말하셨습니다..."우리가 만든 API서버는 비동기로 동작한다. 그래서 비동기에 대한 처리를 해야한다" 그런데 done()이라는 콜백함수를 호출하는 것이 어떤의미에서 비동기에 대한 처린인지 이해가 가지않아 질문을 남깁니다.

  • node.js
  • express
  • tdd
  • rest-api
가보자!! 댓글 1 좋아요 0 조회수 504

선생님 Props내려줄때

미해결

따라하며 배우는 리액트 A-Z[19버전 반영]

data 프롭의 경우는 이미 id ,title, completed 같은 정보들이 다 들어있는거니까 data프롭만 내려받아서 List.js에서 .id, .title, .completed로 써도 문제가 없는거죠?

  • react
  • redux
  • tdd
  • typescript
  • next.js
바퀴Roach 댓글 1 좋아요 0 조회수 356

응답 강의중 질문입니다

미해결

테스트주도개발(TDD)로 만드는 NodeJS API 서버

Pdf 파일에 "204:내용없음, DELETE"라고 되어 있어 질문이 생겼습니다. 204는 삭제요청을 했는데 내용 없을때 리턴해주는 상태 코드인건가요?? Get요청을 했는데 없을시에도 204를 리턴해 주어도 될까요? 3xx 잘가~ 는 어떤 의미로 받아들여야 할지...이해가 가지 않습니다...

  • node.js
  • express
  • tdd
  • rest-api
가보자!! 댓글 1 좋아요 0 조회수 396

요청 형식 강의 질문입니다

미해결

테스트주도개발(TDD)로 만드는 NodeJS API 서버

HTTP경로로 자원을 식별한다고 알려주셨는데! lecture?user={id} 와 같은 식으로는 사용하지 않는건가요?

  • node.js
  • express
  • tdd
  • rest-api
가보자!! 댓글 1 좋아요 0 조회수 471

비동기 세계1 강의 내용 질문입니다

미해결

테스트주도개발(TDD)로 만드는 NodeJS API 서버

노드는 기본적으로 비동기로 동작한다라는 텍스트가 있는데! console.log()를 출력해보면 동기로 동작하는걸 볼 수 있습니다....기본적으로 위에서 아래로 동기로 동작하는데 비동기로 동작하는 함수가 많다는 의미의 텍스트 일까요?

  • node.js
  • express
  • tdd
  • rest-api
가보자!! 댓글 2 좋아요 0 조회수 553

handleSubmit을 useCallback으로

해결됨

따라하며 배우는 리액트 A-Z[19버전 반영]

handleSubmit를 useCallback으로 감싸서 만들어봤는데 const handleSubmit = useCallback( (e) => { e.preventDefault(); let newTodoData = todoData.map((data) => { if (data.id === id) { data.title = editedTitle; } return data; }); console.log(newTodoData); setTodoData(newTodoData); setIsEditing(false); }, [todoData, setTodoData, id, editedTitle] ); 의존성배열에 setTodoData 를 넣지않으면 아래오류가 나면서 handleSubmit 함수가 실행되지 않더라구요 React Hook useCallback has a missing dependency: 'setTodoData'. Either include it or remove the dependency array. If 'setTodoData' changes too often, find the parent component that defines it and wrap that definition in useCallback 제 지식으론 의존성배열에 todoData만 넣으면 될줄 알았는데 왜 setTodoData 까지 같이 넣어야하는지 궁금합니다!

  • react
  • redux
  • tdd
  • typescript
  • next.js
뽀개즈아 댓글 1 좋아요 0 조회수 475

axios.js 에 인스턴스를 만든 후 Banner.js 에 import 할 때 문의

미해결

따라하며 배우는 리액트 A-Z[19버전 반영]

안녕하세요! axios.js 에 인스턴스를 만들고 그 인스턴스를 export default instance; 로 export 해줬는데 그렇다면 Banner.js 에서 가져와서 사용할 때 import instance from "../api/axios"; 라고 가져와서 instance.get(requests.fetchNowPlaying); 이런 식으로 사용하는게 맞지 않나 생각이 들어서 질문 드립니다.

  • react
  • redux
  • tdd
  • typescript
  • next.js
Donald 댓글 1 좋아요 1 조회수 604

Lists.js에서 List컴포넌트로 프롭스 보내줄때,

해결됨

따라하며 배우는 리액트 A-Z[19버전 반영]

<List key={data.id} id={data.id} title={data.title} completed={data.completed} todoData={todoData} setTodoData={setTodoData} provided={provided} snapshot={snapshot} /> List에 프롭스 key를 넘겨주었는데 왜 List.js에서는 key를 받지 않은 건가요?

  • react
  • redux
  • tdd
  • typescript
  • next.js
뽀개즈아 댓글 1 좋아요 1 조회수 369

나만의미니프로젝트 cheerio관련질문

해결됨

[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스

원하는 키워드의 값을 담은 상수를 console.log(key,value) 하면 줄바꿈되면서 안에 있는 전체 값들이 나오더라구요 ( const key = $(el).attr("property").split(":")[1]; const value = $(el).attr("content"); 부분입니다) 근데 이 값들을 db에 저장하려 for문을 이용해 배열에 넣어봤더니 console.log(key,value)해서 나온 값들이 아닌 마지막 값만 들어갑니다 key와 value에 어떤 형태로 값이 스크랩핑되어 들어가있는건가요..? 상수에 배열형태로 들어간 것도 아니고 한줄로 값이 들어간 것도 아니고 .. console.log하면 전체가 나오기는 하나 줄바꿈이 되어 나와서 갈피를 못잡겠습니다.. 스크래핑한 값을 어떻게 저장을하고 넘겨야할지 db로 넘겨야할지 전혀 모르겠습니다................................. 이틀동안 찾아봐도 해결이 안되어서 질문 남깁니다..

  • node.js
  • NestJS
  • express
  • tdd
  • nodejs
  • rest-api
  • javascript
  • nestjs
  • docker
dada dodo 댓글 1 좋아요 0 조회수 577

오류 질문

미해결

따라하며 배우는 리액트 A-Z[19버전 반영]

검색을 해보니 컴포넌트 명 관련해서 에러 라고 나와져있는데 소스 를 확인해봐도 오타 문제는 아닌거같아 강사님께 여쭤봅니다 ㅠㅜ 무슨문제일까요 ?

  • tdd
  • typescript
  • react
  • redux
  • Next.js
junwoo 댓글 1 좋아요 0 조회수 547

인기 태그

인프런 TOP Writers

주간 인기글