공식문서 따라하기
Installing · Express.js 5.x
Learn how to install Express.js in your Node.js environment, including setting up your project directory, managing dependencies with npm, and configuring TypeScript. Documentation for Express.js 5.x.
expressjs.com
시작할때 가장 쉬운 방법은 공식문서를 따라하는 것이다. 하지만 공식문서를 보면 완벽하게 설명해주지 않는다.
따라서 부분적으로 추가내용이 필요하다.
Installing을 끝내고
TypeScript가 필요하지 않는 사람도 있겠지만, 이번에 개인 프로젝트를 시작하면서 TypeScript를 공부하기 위해 추가하려고 한다.
TypeScript를 설치하고 tsconfig.json과 src/app.ts까지 만들었다면 app.ts에서 ts 오류가 나타날 것이다.
이것은 CommonJS(CJS)와 ES Module(ESM)때문에 발생한다.
package.json을 열어서 type을 보면 "commonjs" 라고 되어있는 것을 "module"로 변경해야한다.
{
"type": "commonjs"
}
{
"type": "module"
}
이제 실행을 하면 오류 없이 실행이 되고 localhost:3000에 접속하면 "Hello World!"를 볼 수 있을 것이다.
