반응형

개발 창고/NodeJS 35

[React] Nginx 새로고침 404 에러 수정

location / { try_files $uri $uri/ /index.html =404; } React를 배포하고, Nginx를 활용하여 서비스를 실행한 경우, index.html을 통하여 원하는 페이지로 이동 시에는 잘 넘어 가지만, 이동한 페이지에서 새로고침(F5)을 하는 경우 404 에러를 발생하게 됩니다. 이를 해결하기 위해서는, 새로고침으로 전달된 uri 정보를 index.html를 통하여 uri로 이동하도록 설정을 해주어야 합니다. server { listen 80; server_name localhost; #access_log logs/localhost.log combined; location / { try_files $uri $uri/ /index.html = 404; root /dat..

[Express] 파일 다운로드

res.download(path [, filename] [, options] [, fn]) path : 다운로드할 파일의 경로 filename : 다운로드 받을 파일 이름 options : 다운로드 설정 fn : callback 처리 사용방법 const express = require('express'); const app = express(); /** * 첨부파일 다운로드 */ app.get('/api/file/download', async(req, res) => { const filepath = "/filepath/filename.txt" const filename = "downfile.txt"; if(fs.existsSync(filepath)){ res.download(filepath, filena..

[React] 상대경로 설정하기

// jsconfig.json { "compilerOptions": { "baseUrl": "src" }, "include": [ "src" ] } React에서 내부 컴포넌트를 import시에 기본적으로는 아래와 같이 사용하곤 합니다. 1번 라인에 보면 ../../../utils/CommonUtils 라고 되어있는데, 만약 아래와 폴더구조가 같다면 src ├─ utils │ └ CommonUtils.js └─ view └ front └ comp └ CondMonth.js 현재 CondMonth.js라는 파일이 있는 폴더(comp)의 상위 폴더(front)의 상위 폴더(view)의 상위 폴더(src)에서 utils 폴더의 CommonUtils.js를 import 합니다. 이는 두 가지 측면에서 개발의 어..

[CentOS] npm 실행 Service 등록

$> sudo vi /etc/systemd/system/{서비스 이름}.service [Unit] Description={서비스 설명} [Service] Type=simple Restart=always User=root Group=root WorkingDirectory={Root 폴더} ExecStart=/usr/bin/npm start [Install] WantedBy=multi-user.target $> sudo systemctl enable {서비스 이름}.service $> sudo systemctl start {서비스 이름}.service {서비스 이름} : 만들고자 하는 서비스의 이름 {서비스 설명} : 해당 서비스에 대한 간단한 Description {Root 폴더} : 해당 node 프로젝..

[Puppeteer] Element Exists

// 아이템 체크 let exists = false; try { // 현재 selector >> "#gnb .group_nav .list_nav .nav_item" exists = await page.$eval("#gnb .group_nav .list_nav .nav_item", ele => ele?true:false); }catch (e){ // 에러 처리 console.log(e); } puppeteer를 사용하다 보면 유효성 검사를 위해 해당 element가 있는지 확인해봐야 하는 경우가 있습니다. 만약 위와 같이 네이버 메인의 GNB 첫 번째 항목을 클릭 하는 puppeteer를 생성하려고 합니다. 그런데 만약, 네이버가 메인화면 개편을 하여, 해당 항목으로 가는 selector의 정보가 변경되면..

[Puppeteer] 현재 페이지 URL 가져오기

puppeteer에서 현재 페이지를 가져오려면 page.url() 을 쓰면 됩니다. const puppeteer = require('puppeteer'); (async function main() { try { const browser = await puppeteer.launch({ headless : false, executablePath : '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', }); const page = await browser.newPage(); await page.goto('https://naver.com/'); console.log(page.url()); console.log(typeof page.url()); aw..

[Database] My Batis 설치

이전 mssql connection 내용을 먼저 참조하시는게 좋습니다. 2022.05.03 - [분류 전체보기] - [NodeJS] MSSQL DB Pool 설정 [NodeJS] MSSQL DB Pool 설정 0. mssql 모듈 설치 $> npm i mssql 1. db config 파일 생성 : 서버와 개발환경 분리를 위하여, config파일은 분리하여 관리하는 것이 좋습니다. // dbconfig.js module.exports = { port:{DB서버 포트} , user:.. royzero.tistory.com 0. 모듈 설치 $> npm i --save mybatis-mapper 1. xml 생성 : TestSQL.xml 파일 생성 SELECT COL1 , COL2 FROM TEMP WHERE..

[Database] MSSQL DB Pool 설정

이 버전에서는 TOC를 지원하지 않습니다. (ex. 모바일) 0. mssql 모듈 설치 $ npm i mssql 1. db config 파일 생성 : 서버와 개발환경 분리를 위하여, config파일은 분리하여 관리하는 것이 좋습니다. // dbconfig.js module.exports = { port:{DB서버 포트} , user:'{계정아이디}' , password:'{계정비밀번호}' , server:'{DB서버 아이피}' , database:'{데이터베이스 명}' , options: { encrypt: true, // Use this if you're on Windows Azure } , pool: { max: 5, min: 1, idleTimeoutMillis: 30000, } , trustSer..

[FileSystem] 폴더 내 목록 불러오기

node에서 로컬의 파일을 다루기 위해서는 내장 모듈인 fs (File System) 모듈이 필요합니다. 15.x 버전 기준의 함수 목록은 아래의 링크에서 확인 가능합니다 https://nodejs.org/docs/latest-v15.x/api/fs.html#fs_file_system 만약 아래와 같이 fs_test 폴더 내에 files 폴더가 있는 구조이고, 이 files 폴더 내 파일들의 목록을 출력한다면 아래와 같이 fs_test 폴더 내에 main.js를 작성하여 const fs = require('fs');// fs 모듈 선언 const folder = './files';// 폴더 경로 값 지정 fs.readdir(folder, function(error, filelist){ console.lo..

반응형