MYSTAGRAM 제작기 7

Dreambuilder·2021년 5월 30일
0

mystagram

목록 보기
7/7

파일 업로드

graphql에서는 upload type을 제공하여 쉽게 파일을 업로드할 수 있다.

파일 업로드 설명

graphql에서 제공하는 playground에서는 파일을 첨부할 수 없다. 그래서
altair을 활용한다.

오류 다루기

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::4000
    at Server.setupListenHandle [as _listen2] (net.js:1316:16)
    at listenInCluster (net.js:1364:12)
    at Server.listen (net.js:1450:7)
    at /Users/tyflow/mystagram-backend/node_modules/apollo-server/src/index.ts:152:18
    at new Promise (<anonymous>)
    at ApolloServer.<anonymous> (/Users/tyflow/mystagram-backend/node_modules/apollo-server/src/index.ts:147:11)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/tyflow/mystagram-backend/node_modules/apollo-server/dist/index.js:15:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Emitted 'error' event on WebSocketServer instance at:
    at Server.emit (events.js:314:20)
    at Server.EventEmitter.emit (domain.js:483:12)
    at emitErrorNT (net.js:1343:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  code: 'EADDRINUSE',
  errno: 'EADDRINUSE',
  syscall: 'listen',
  address: '::',
  port: 4000
}

해당 오류는 코드 수정 후 리빌드될 때 이전에 실행됬던 서버를 죽이고 실행되어야 하는데 죽이기 전에 실행됬을 때 나는 오류이다.

nodemon --exec babel-node server --delay 2

이렇게 delay를 주면 오류에 대응할 수 있다.

ApolloServer와 express 함께 쓰기

const PORT = process.env.PORT;

const app = express();
server.applyMiddleware({ app });
app.listen({ port: PORT }, () => {
  console.log(`🚀Server is running on http://localhost:${PORT} ✅`);
});

morgan

morgan은 nodeJS 에서 사용되는 로그 관리를 위한 미들웨어이다.

morgan 설명

profile
상상이 실현되는 곳

0개의 댓글