일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Linux pwd
- Navigation Pattern
- Linux rmdir
- EC2 Apache2
- Logback
- Linux 디렉터리 구조
- linux background
- EC2 zsh
- Linux apt-get
- Linux cd
- HTTP Web Server
- javascript scope
- 자바스크립트 런타임
- EC2 HTTP 호스팅
- Linux 디렉터리 명령어
- AWS EC2 서버 만들기
- linux foreground
- Linux ls
- EC2 oh my zsh
- 자바스크립트 이벤트 루프
- JavaScript 실행 디버깅
- 서버의 서비스 방식
- Linux mkdir
- Linux oh my zsh
- JavaScript EventLoop
- Linux 디렉터리 역할
- Linux apt
- Linux cat
- javascript 정렬
- Linux 파일 관리 명령어
Archives
- Today
- Total
HyunJun 기술 블로그
Node.js & Express 설치 본문
728x90
반응형
Node.js 설치
1) GUI 환경.
https://nodejs.org/ko -> LTS Download -> 설치 (node.js 설치 시 npm 자동 설치됨.)
2) CLI 환경.
nvm (Node Version Manager) 설치
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
$ source $HOME/.zshrc nvm ls-remote node nvm install v16.15.1
$ nvm --version
0.39.1
node.js 설치
$ nvm install --lts
Installing latest LTS version.
Downloading and installing node v18.17.1...
Downloading https://nodejs.org/dist/v18.17.1/node-v18.17.1-linux-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.17.1 (npm v9.6.7)
Creating default alias: default -> lts/* (-> v18.17.1)
$ node --version
v18.17.1
Node.js 프로젝트 생성
1) app.js 생성
VS Code Project 생성 -> 터미널 - > npm init 입력 후,
- package name:
- version:
- description:
- entry point: app.js
- test command:
- git repository:
- keywords: node test
- author: 제작자
- license: (ISC)
- Is this OK? (yes) yes
hyunjun@MacBook-Pro kyungil-node % 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: (kyungil-node) com.test
version: (1.0.0)
description: nodejs install
entry point: (index.js) app.js
test command:
git repository:
keywords: node test
author: hyunjun
license: (ISC)
About to write to /Users/hyunjun/Library/Mobile Documents/com~apple~CloudDocs/IT/kyungil/kyungil-node/package.json:
{
"name": "com.test",
"version": "1.0.0",
"description": "nodejs install",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"node",
"test"
],
"author": "hyunjun",
"license": "ISC"
}
Is this OK? (yes) yes
위의 npm init 과정을 거치면, 패키지와 프로젝트의 정보를 기록하고 관리하는 파일인 package.json 파일이 생성된다.
2) express 설치
hyunjun@MacBook-Pro kyungil-node % npm install --save express
added 58 packages, and audited 59 packages in 674ms
8 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
hyunjun@MacBook-Pro kyungil-node %
package-lock.json 파일이 생기며, node_modules라는 폴더가 생긴다.
3) app.js 기본 코드
app.js라는 파일을 생성한다.
기본 Controller 코드 작성
const express = require("express");
const app = express();
app.get("/", function (req, res) {
res.send("Hello World");
});
app.listen(3000, function () {
console.log("3000 port listen");
});
4) 앱 실행(서버 실행)
hyunjun@MacBook-Pro kyungil-node % node app.js
3000 port listen !!
5) 테스트
브라우저로 localhost:3000 접속.
728x90
반응형
Comments