상세 컨텐츠

본문 제목

1. intro & 2. SET UP

노마드/유튜브

by hippo0207 2022. 8. 8. 21:57

본문

  • express, mongoDB, NodeJS
  • HTML5, css3, pug

What is NodeJS

브라우저 밖에서 돌아가는 자바스크립트. 프로그래밍언어화 시킴

NPM

  • 자바스크립트 언어를 위한 패키지매니저
  • yarn이랑 비슷
  • nodeJS랑 같이써야함, 같이설치됨. 이미설치됐음
  • node명령어보다 npm명령어를 많이쓰게될거임
  • 여기있는 패지지중 하나가 express임

2.0 Set UP

  • 1. package.json 생성 > 근데 직접안만들거임
  • 2. 터미널에서 npm으로 만들거임
 npm init
 ~~엔터쭉쭉
 license는 MIT로 했음
 =======
 {
  "name": "youtube",
  "version": "1.0.0",
  "description": "The best way to wawtch videos",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Youngju-Jang/youtube.git"
  },
  "author": "Youngju Jang<joj1043@github.com>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/Youngju-Jang/youtube/issues"
  },
  "homepage": "https://github.com/Youngju-Jang/youtube#readme"
}
=================
script는 지웠음
  • 1. index.js 생성

2.1 installing Express

  • node로는 실행안할거임
  • 1. package.json에 scripts 추가 << 실행하고싶은것 넣음
 "scripts": {
    "win":"node index.js"
  },
  • 2. npm run win
  • 3. npm i(install) express
    • node_module 생김 >> npm으로 설치한 모든 패키지 저장됨
    • dependencies : express실행할때 필요한조건 >> 다운받은거임
  • 4. node_module 폴더  & package-lock.json삭제하기

2.2 Dependencies

  • 삭제한 다음 npm i  만 실행 (express 없이)  << package.json 닫고 실행할것
  • >> npm 이 내 package.json > dependencies보고서 알아서 설치함
  • 프로그램 동작시 필요한 모듈들의 정보가짐
  • 프로젝트 공유시 dependencies만 있으면 node_module다 공유할필요 없음
  • package-lock : 패키지 안전하게 관리
  • .gitignore 파일생성 >> /node_modules 추가

2.3 The Tower of Babel : Babel is a JavaScript compiler.

  • nodeJS가 아직 이해못하는 자바스크립트도 있음 >> babel사용
  • 최신 자바스크립트 컴파일해줌
  • 1. nodeJS를 위한 babel사용해야함 >> 사이트에서 setup > nodeJS > 
  • 2. npm install --save-dev @babel/core  실행 >> devDependencies 추가됨
  • devDependencies = 개발자에게 필요한 dependencies
  • --save-dev >> 이게 있어야 devDependencies로 감
  • 3. babel.config.json 파일생성 & 파일에 아래코드 추가
{
  "presets": ["@babel/preset-env"]
}
  • 4. npm install @babel/preset-env --save-dev 설치
  • preset : plugin임

2.4 Nodemon

  • babel 기존방식 

  • >> 이거대신 package.json에 babel로 컴파일하는 scripts 만들거
  • 1. npm install --save-dev @babel/node
  • 2. scripts에 추가
"scripts": {
    "dev": "babel-node index"
  },
  • 이제 알아서 nodeJS실행하면 babel도 실행됨
  • 이제 index.js 위에내용도 수정가능
//const express = require("express");
//>> babel설치하면 밑에처럼 사용가능
import express from "express";

const app = express();

console.log("Hi!");
  • 매번 npm run dev 하기 귀찮음 >> nodemon 사용하면 됨
  • : 모든파일이 수정되는걸 감지 & 재시작해줌
    • 1. npm install nodemon --save-dev  로 설치
    • 2. scrips 수정
"scripts": {
    "dev": "nodemon --exec babel-node index"
  },

 

'노마드 > 유튜브' 카테고리의 다른 글

ch6. mongoDB & Mongoose  (0) 2022.08.16
ch5.7~ conditionals, iteration, mixins  (0) 2022.08.16
ch5. Templates  (0) 2022.08.14
ch4. Routers  (0) 2022.08.11
ch3. express intro  (0) 2022.08.09

관련글 더보기

댓글 영역