package.json 파일 생성하기
- Node.js 프로젝트의 정보를 저장하는 파일을 생성해본다.
- vscode를 실행한 후, 새 폴더를 생성한다.
- vscode에서 폴더를 불러온다.
- 보기>터미널을 선택하여 터미널을 연다.
- npm init을 입력 후 엔터를 연타한다.
PS D:workspaces\\nodejs> npm init
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
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: (nodejs)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to D:workspaces\\nodejs\\package.json:
{
"name": "nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \\"Error: no test specified\\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this OK? (yes)
npm notice
npm notice New minor version of npm available! 8.11.0 -> 8.15.0
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.15.0>
npm notice Run npm install -g [email protected] to update!
npm notice
PS D:workspaces\\nodejs>
자바스크립트 파일 생성 및 실행하기
- package.json 파일에 명시된 main 항목의 index.js를 다룬다.
- 탐색기 우측 상단의 새 파일을 누르고 index.js를 생성한다.
- console.log("hello, node.js!") 를 입력 후 저장한다.
- 터미널에 node index 명령을 실행하거나, 다음을 설정한다:
- 좌측 메뉴의 실행 및 디버그 버튼을 클릭한다.
- launch.json 파일 만들기를 클릭한다.
- Node.js를 클릭한다.
- launch.json 파일이 생성되었다면, 다시 index.js로 돌아간 뒤 좌측 상단의 초록 화살표를 클릭한다.