공부/[TIL] Digital Twin Bootcamp

TIL_220215_환경구축

2022. 2. 15. 13:25
목차
  1. 과제
  2. 처음 보는 에러 기록
  3. sequelize DB 연동 확인 코드
  4. Collaborators 추가
  5. 유의사항
  6. Conflict
  7. Docker 컨테이너에서 postgresql 실행하기

이제 이론은 거의 다 끝났고 프로젝트 위주로 앞으로 진행 된다.

팀 프로젝트 2개 + 개인 프로젝트 1개인데

개인 프로젝트는 틈틈히 열심히 해야한다. 아자아자 화이팅!

 

과제

1. git/github 자신 개인프로젝트 빈 레포지토리(front/back) 만들기
2. 프론트엔드
(1) 로컬환경에서 프로젝트 폴더 만들고 git 초기화하고 main 브랜치 만들기
(2) remote 정보 추가 (front 원격 레포지토리)
(3) 프로젝트 폴더 안에서, vue.js에 필요한 패키지 설치하고 실행 잘되는지 확인해보기
(4) 실행이 잘되면, github에 푸쉬하기
3. 백엔드
(1) 로컬환경에서 프로젝트 폴더 만들고 git 초기화하고 main 브랜치 만들기
(2) remote 정보 추가 (backend 원격 레포지토리)
(3) 프로젝트 폴더 안에서, nodejs 백엔드에 필요한 패키지 (express, sequelize) 설치하고, 실행 잘되는지 확인해보기
(4) 실행이 잘되면, github에 푸쉬하기
4. git/github 팀 프로젝트 빈 레포지토리(front/back) 만들고, 팀원 콜라보레이터 추가하기 5. 2,3 번과 동일하게 진행

 

처음 보는 에러 기록

백엔드

app.js 파일에서 모듈을 불러오는 경로에 다음과 같은 에러가 났다.

eslintimport/no-unresolved

eslint 경로 에러였다. 링크대로 명령어를 넣어 해결했다.

https://xxxxersuy.com/19

 

eslint 경로 에러와 절대경로 지정(.eslintimport/no-unresolved)

eslint 의 경로에 경고가 뜨는 에러 eslint 를 설치를 하고 메인 페이지를 작성을 했는데,경고가 나왔다. 위 이미지를 봤을 때 처럼 경고가 나온다. > module "/Users/xers/Desktop/local_xers/proj/github/custo..

xxxxersuy.com

module.exports = {
  env: {
    browser: true,
    commonjs: true,
    es2021: true,
    es6: true,
    node: true,
  },
  extends: ['airbnb-base'],
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly',
  },
  parserOptions: {
    ecmaVersion: 2018,
  },
  rules: {
    'linebreak-style': 0,
    'no-unused-vars': ['warn', { vars: 'all', args: 'after-used', ignoreRestSiblings: false }],
    'import/no-unresolved': [
      'error',
      { caseSensitive: false },
    ],
  },
};

 

sequelize DB 연동 확인 코드

app.js

const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
// const logger = require('morgan');
const bodyParser = require('body-parser');
const cors = require('cors');
const corsConfig = require('./config/corsConfig.json');
const models = require('./models/index');
const logger = require('./lib/logger');

const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');

const app = express();
logger.info('app start');

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// DB 연결 확인 및 table 생성
models.sequelize.authenticate().then(() => {
  logger.info('DB connection success');

  // sequelize sync (table 생성)
  models.sequelize.sync().then(() => {
    logger.info('Sequelize sync success');
  }).catch((err) => {
    logger.error('Sequelize sync error', err);
  }).catch((err) => {
    logger.error('DB Connection fail', err);
  });
});

app.use(express.static(path.join(__dirname, 'public')));

// app.use(logger('dev'));
app.use(cors(corsConfig));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use('/', indexRouter);
app.use('/users', usersRouter);

// catch 404 and forward to error handler
app.use((req, res, next) => {
  next(createError(404));
});

// error handler
app.use((err, req, res, next) => {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});
app.listen(app.get('port'), () => {
  console.log(app.get('port'), '번 포트에서 대기중');
});

module.exports = app;

models/connection.js

const Sequelize = require('sequelize');
const dotenv = require('dotenv');

dotenv.config(); // .env 파일 불러오기

const db = {
  username: process.env.DB_ID,
  password: process.env.DB_PASS,
  database: process.env.DB_DATABASE,
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  dialect: process.env.DB_DIALECT,
};

// sequelize 생성
const sequelize = new Sequelize(
  db.database,
  db.username,
  db.password,
  {
    host: db.host,
    port: db.port,
    dialect: db.dialect,
  },
);

exports.sequelize = sequelize;

models/index.js

const { sequelize } = require('./connection');

const db = {};

db.sequelize = sequelize;

module.exports = db;

 

연동 확인

 

Collaborators 추가

 

git fetch : github의 branch들 가져오기(업데이트)

 

유의사항

pull request 할 때 main branch 말고 develop branch 따로 만들어서 커밋해줄것(원본은 늘 남겨둬야함)

 

Conflict

똑같은 부분이 수정된 경우(수정이 중복된 경우) 우선순위를 무엇을 줄 지 결정할 땐 pull로 다운 받아서 코드를 먼저 merge 해보고 잘 되면 그때 push 해야 함

VIsual Code로 하면 추가 기능을 사용할 수 있어 간편하다. 수동으로 수정해도 된다.

 

 

Docker 컨테이너에서 postgresql 실행하기

docker 파일을 바탕으로 이미지 생성(postgresql)

docker build -t postgres:dev .

만들어진 이미지를 바탕으로 컨테이너 생성

PS C:\Users\user\Desktop\220215 docekr_postgres> docker run -dit -p 5433:5432 -e POSTGRES_PASSWORD=postgres --name postgresDB postgres:dev
ce701b40b2b2252b142eb109ae84947f5a71aa44d5ba20c181b551c88ce7f87a
PS C:\Users\user\Desktop\220215 docekr_postgres> docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                    NAMES
ce701b40b2b2   postgres:dev   "docker-entrypoint.s…"   7 seconds ago   Up 5 seconds   0.0.0.0:5433->5432/tcp   postgresDB

DBeaver에서 확인

새 데이터베이스 연결

설정한 포트와 패스워드 입력
확인 완료

'공부 > [TIL] Digital Twin Bootcamp' 카테고리의 다른 글

TIL_220211_인공지능  (0) 2022.02.11
TIL_220210_IIoT CPS / 클라우드 컴퓨팅  (0) 2022.02.10
TIL_220209_Git / Docker  (1) 2022.02.09
TIL_220208_DevOps / Docker  (0) 2022.02.08
TIL_220207_DevOps/Git/Github  (0) 2022.02.07
  1. 과제
  2. 처음 보는 에러 기록
  3. sequelize DB 연동 확인 코드
  4. Collaborators 추가
  5. 유의사항
  6. Conflict
  7. Docker 컨테이너에서 postgresql 실행하기
'공부/[TIL] Digital Twin Bootcamp' 카테고리의 다른 글
  • TIL_220211_인공지능
  • TIL_220210_IIoT CPS / 클라우드 컴퓨팅
  • TIL_220209_Git / Docker
  • TIL_220208_DevOps / Docker
Ail_
Ail_
Ail_
log
Ail_
  • 분류 전체보기 (180)
    • 사설 (11)
      • 강연 (5)
      • * (3)
      • 회고 (3)
    • 공부 (160)
      • Just do it (3)
      • TIL (66)
      • [TIL] Game Bootcamp (30)
      • [Project] Game Bootcamp (1)
      • [TIL] Digital Twin Bootcamp (39)
      • [Project] Digital Twin Boot.. (21)
    • 노션 (3)

인기 글

최근 글

태그

  • 유니티 게임 개발
  • 개발회고
  • 피격
  • TypeScript
  • 데이터베이스
  • SQL첫걸음
  • 티스토리챌린지
  • mysql 설치
  • 배포
  • node.js
  • Do it! 자료구조와 함께 배우는 알고리즘 입문 : 파이썬 편
  • Chat
  • 오블완
  • SQL 첫걸음
  • unity
  • 템플릿
  • 유니티
  • 회고
  • 대시
  • 개발일지
  • 한입 크기로 잘라 먹는 타입스크립트
  • 플레이어
  • 노션
  • 멋쟁이사자처럼
  • 부트캠프
  • 이펙트
  • notion
  • 인터랙티브 웹 UX·UI
  • 공격
  • C#

최근 댓글

전체
오늘
어제
hELLO · Designed By 정상우.
Ail_
TIL_220215_환경구축
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.