package.json 파일 생성하기


  1. vscode를 실행한 후, 새 폴더를 생성한다.
  2. vscode에서 폴더를 불러온다.
  3. 보기>터미널을 선택하여 터미널을 연다.
  4. 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>

자바스크립트 파일 생성 및 실행하기


  1. 탐색기 우측 상단의 새 파일을 누르고 index.js를 생성한다.
  2. console.log("hello, node.js!") 를 입력 후 저장한다.
  3. 터미널에 node index 명령을 실행하거나, 다음을 설정한다: