본문 바로가기

javascript/nodejs

(17)
[nodejs] thread pool 참고 자료 유튜브 채널: https://www.youtube.com/watch?v=3JYNNf3Iljo libuv, nodejs 공식 문서 및 깃허브 node의 이벤트 루프가 싱글 스레드 기반으로 동작하기는 하지만, 내부적으로 들어가면 시간이 오래 걸리는 특정 작업(File I/O, DNS 등)의 경우 libuv 라이브러리가 제공하는 스레드 풀을 이용하여 처리한다. https://docs.libuv.org/en/v1.x/threadpool.html#threadpool libuv에서 스레드 개수는 UV_THREADPOOL_SIZE 환경 변수로 나타나며 기본 값은 4이다. 이 값은 변경할 수 있으며, 최대 1024의 값을 가질 수 있다. 병렬성 수준 nodejs는 os 모듈의 cpus().length 또는 ..
[nodejs] libuv 이미지 출처: https://docs.libuv.org/en/v1.x/index.html 도움: chatgpt, stackoverflow 등. chatgpt는 부정확한 내용이 조금 있어서 구글링 도움을 많이 받음. 노드는 비동기 + 이벤트 기반 모델을 기반으로 작동한다. 일반적으로 single thread, non-blocking I/O, event loop를 노드의 특징으로 설명하는데, 이러한 핵심 동작 원리는 내부적으로 C언어 기반으로 작성된 libuv가 수행한다. libuv libuv는 Node.js의 이벤트 기반 비동기 I/O 모델을 지원하기 위해 작성된 크로스 플랫폼 라이브러리로, 노드는 내부적으로 시간이 오래 걸리는 작업(File I/O, DNS 연산 등)을 libuv에 위임하여 처리한다. 해..
[nodejs] esbuild 전체 폴더 감시하기 https://esbuild.github.io/ esbuild - An extremely fast bundler for the web esbuild An extremely fast bundler for the web Above: the time to do a production bundle of 10 copies of the three.js library from scratch using default settings, including minification and source maps. More info here. Our current build tools for the web ar esbuild.github.io esbuild는 많은 번들링 툴(여러 코드 베이스를 하나로 뭉치기) 중 하나로, 공식 ..
[nodejs] express-session typescript와 사용하기 express-session 모듈을 사용할 때 데이터는 req.session.~ 형태로 추가한다. 이때 추가되는 객체는 @types/express-session을 따로 설치하더라도 인식되지 않는다. 따라서 따로 타입 정의를 해줘야 한다. 타입 정의를 작성할 파일은 tsconfig.json 파일 내에 rootDir로 정의된 경로 내에 존재해야 타입 추론이 정상적으로 진행되는 것으로 보이며, 방법은 크게 2개로 나뉜다. src/@types 폴더 내 *.d.ts 파일 내에 정의한다. src/global.d.ts 파일 내에 정의한다. 두가지 방법 중 어떤 방법을 선택했다고 가정하고, req.session의 구조를 살펴보자. /** * This request's `Session` object. * Even tho..
[nodejs] prisma ORM 라이브러리 https://www.prisma.io/ Prisma | Next-generation ORM for Node.js & TypeScript Prisma is a next-generation Node.js and TypeScript ORM for PostgreSQL, MySQL, SQL Server, SQLite, MongoDB, and CockroachDB. It provides type-safety, automated migrations, and an intuitive data model. www.prisma.io prisma는 타입스크립트 환경에서 사용 가능한 ORM 라이브러리 중 하나로, 모델의 정의를 자바스크립트 또는 타입스크립트 파일에 선언하는 대신 prisma schema라는 별도의 설정 파일을..
[nodejs] mysql2 라이브러리 mysql2 https://github.com/sidorares/node-mysql2 GitHub - sidorares/node-mysql2: fast mysqljs/mysql compatible mysql driver for node.js :zap: fast mysqljs/mysql compatible mysql driver for node.js - GitHub - sidorares/node-mysql2: fast mysqljs/mysql compatible mysql driver for node.js github.com mysql2 라이브러리는 nodejs 환경에서 mysql에 접근하기 쉽도록 도와주는 라이브러리로, 기존에 별도로 존재하던 라이브러리를 대중적으로 사용되던 mysql 라이브러리와 동일한..
[오늘의 삽질] web-tree-sitter 과 emscripten https://tree-sitter.github.io/tree-sitter/ Tree-sitter|Introduction Introduction Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited. Tree-sitter aims to be: General enough to par tree-sitter.github.io tree-sitter은 C언어 기반의 파서 생성기? 로 의존성을 최소화하여 다양한 환경에서 ..
[nodejs] __filename & __dirname / join & resolve 때로는 파일 혹은 폴더의 절대 경로가 필요할 때가 있다. nodejs에서는 __filename 및 __dirname을 통해 현재 작업중인 폴더 및 파일의 절대 경로를 알 수 있도록 지원하고 있다. console.log(`dirname : ${__dirname}`) console.log(`filename : ${__filename}`) 앞서 언급한 것처럼 __dirname 및 __filename 은 해당 파일의 현재 위치와 관련된 정보를 반환하므로, 다른 파일에서 특정 파일의 절대 경로를 이용할 수도 있다. # index.cjs const folderDir = require('./fol2/myfile.cjs'); console.log(folderDir.basedir); # fol2/myfile.cjs co..