koa 프로젝트 세팅

Jaymee·2021년 9월 20일

nodejs 프레임워크 중에 express 말고 koa 라는 새로운 프레임워크를 사용해보고자 한다.
koa는 express 개발자들이 새롭게 만든 프레임워크라고 한다.

기존에 사용하던 node를 가지고 koa를 개발하고자 하면

$ yarn add koa
$ yarn add koa-router
$ yarn add koa-bodyparser

error koa@2.13.1: The engine "node" is incompatible with this module. Expected version "^4.8.4 || ^6.10.1 || ^7.10.1 || >= 8.1.4". Got "8.1.2"

$ yarn add -D typescript
$ yarn add -D ts-node
$ yarn add -D nodemon
$ yarn add -D @types/koa
$ yarn add -D @types/koa-router
$ yarn add -D @types/koa-bodyparser

error @cspotcode/source-map-support@0.6.1: The engine "node" is incompatible with this module. Expected version ">=12". Got "8.10.0"

잘 읽어보면 node의 버전이 koa 개발하는데 있어서 중요한 역할을 한다는 것을 알 수 있다.
그러면 node의 버전을 업그레이드 시켜야 하는데...
방법은 여기 잘 나와있다.

혹시
throw new TypeError(``Unexpected ${nextType} at ${index},expected ${type});
와 같은 에러가 생긴다면,

router.get('/*', async (ctx) => {
    ctx.body = 'koa-toy-side-project is starting~';
});

라우팅 path를 보면 * 같은 이상한 삽질이 있다.

참고로 tsconfig.json 파일은

{
  "compilerOptions": {
    "target": "es5",                                
    "module": "commonjs",     
    "outDir": "./dist",           
    "strict": true,                                 
    "noImplicitAny": true,   
    "esModuleInterop": true,      
    "skipLibCheck": true,                           
    "forceConsistentCasingInFileNames": true        
  },
  "include": [
    "./src/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

와 같이 세팅하였다.

profile
backend developer

0개의 댓글