IT/node.js

[Node.js] Nodejs 백엔드 프로젝트 생성하기 1

@욕심쟁이 2021. 9. 26. 23:40
반응형

1. 백엔트 프로젝트 폴더생성

    - back

2. npm init 하면 아래같이 설정에대한 내용이 나옴니다. 

    : 나중에 설정가능한것들이 있어 그냥 엔터 후 yes 하시면 됩니다.

D:\codingSeo\vue>cd back

D:\codingSeo\vue\back>npm init

This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (back) vue-nodebird-back
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to D:\codingSeo\vue\nodeBirdSns\back\package.json:

{
  "name": "vue-nodebird-back",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes) yes

D:\codingSeo\vue\back>npm i express

added 50 packages, and audited 51 packages in 1s

found 0 vulnerabilities

D:\codingSeo\vue\back>

3. 완료 후 폴더에 node_modules와 package-lock.json과 package.json 이 생성됩니다.

 

4. main인이 진입점을 뜻합니다. (가장 중요한파일, 가장 첫번째로 봐야할 파일)

  저는 index.js 를 app.js로 수정 하였습니다.

  ** dev 명령어 실행을 위해 scripts에 "dev" : "node app.js"를 추가합니다.

5. 노드에선 import, export를 사용하지 않고 아래처럼 reqire()를 사용합니다.

express를 사용하여 서버를 실행 시켜서 테스트 해봅시다.

반응형

 

6. 터미널에 npm run dev  라고 실행하면 작동하시는것을 확인하실수 있습니다.

D:\codingSeo\vue\back>npm run dev

> vue-back@1.0.0 dev
> node app.js

백앤드 서버 3000번 모드에서 작동중.

 

반응형