반응형

nodejs 28

[ExcelJS] 내용 덮어 씌우기

const path = require("path"); // 디렉토리 경로 const exceljs = require("exceljs"); // 엑셀 관련 API (async() => { try{ const filename = "excelappend.xlsx"; // 파일명 const template = path.join(__dirname, filename); // 템플릿 파일 위치 const workbook = new exceljs.Workbook(); // Step. Excel Template 파일 Read workbook.xlsx.readFile(template) .then(() => { // Step. 해당 템플릿 엑셀에서 Sheet1번 Sheet를 불러옴 const sheet = workbook...

PDF 이미지 추출하기

※ 해당 글은 아래 Library를 참조하여 작성되었습니다. https://github.com/mablay/pdf-export-images GitHub - mablay/pdf-export-images: Export images from PDF files via CLI Export images from PDF files via CLI. Contribute to mablay/pdf-export-images development by creating an account on GitHub. github.com /** * @file index.js * @install npm i pdf-export-images * @desc PDF에서 이미지 추출 */ // Step. PDF 이미지 추출 라이브러리 선언 (Impo..

[React] Component에서 useParams 사용하기

import React, { Component } from "react"; import { useParams } from "react-router-dom"; function withParams(Component) { return (props) => ; } class CustomComponent extends Component { constructor(props){ super(props); const val1 = props.params.val1; // useParams()로 넘어온 val1 const val2 = props.params.val2; // useParams()로 넘어온 val2 this.state = { val1:val1, val2:val2 }; // Component state에 저장 } r..

[React] String to Html 렌더링

import React from "react"; class App extends React.Component { render(){ let html = "Hello, World"; return ( 그냥 넣는 경우 {html} dangerouslySetInnerHTML을 적용한 경우 ) } } export default App; React에서는 XSS 공격을 막기 위해 일반적으로 사용되는 {} 형태의 렌더링 시에 HTML을 단순 텍스트 형태로만 출력합니다. 때문에, 태그에 사용된 것처럼 dangerouslySetInnerHTML를 활용해줘야 html 태그를 적용하여 표현해 줄 수 있습니다. 이는 db에서 불러오는 html형태의 태그를 불러올 때 활용가능하며, span 대신에 다른 element를 활용해도 상..

[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..

[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..

[React] Router - 페이지 이동 시 스크롤 위치 조정

React를 이용하여 페이지 제작 시에 페이지 이동을 Router를 사용하게 되는데, 이때 기본적으로는 스크롤 위치가 이동하지 않습니다. 흔히 웹페이지를 이용해본 사람이라면, 페이지 이동이나 화면 전환이 된 경우 페이지를 맨 위에부터 보기를 원하는데, Router는 스크롤이 해당 위치에 머물게 됩니다. 이를 해결하기 위해서는, 페이지 이동을 인식한 경우, Scroll의 위치를 조정해주면 되는데, 이에 대한 자세한 내용은 아래의 사이트에 잘 정의되어있습니다. https://v5.reactrouter.com/web/guides/scroll-restoration Declarative routing for React apps at any scale | React Router Version 6 of React R..

개발 창고/Web 2022.06.23

[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..

반응형