บทความ

Prisma

Prisma ref:  https://www.prisma.io/docs/orm

How to Fix “JavaScript Heap Out of Memory Error”

JavaScript heap out of memory problem: Fetching millions of records with MariaDB, Sequelize & Node.js to display in DevExtreme PivotGrid sol:  How to Fix “JavaScript Heap Out of Memory Error” 3.6 million rows. Lets assume each row has  128 bytes  of data, which is  460,800,000 bytes  is  439 mb  of raw data you're trying to select, which doesn't sound too bad. But this data will be wrapped in objects/models/turned to json, so your memory requirement turns out at least roughly ten fold.  4.3GB . Okay, still not too bad. Now we need to push it to browser, style it, wrap it in html, json etc... We're going to push roughly  1.4GB  in json to the client. client downloads happily. The json is in the browser. It's getting turned into an object. Memory times 4 roughly.  5.6GB . Not too shabby, but the browser will have copped out because it has a 256MB memory limit per tab( I've run into this when coding a game, will vary per browser )....

บันทึก

 node -e 'console.log(v8.getHeapStatistics().heap_size_limit)'  node --max-old-space-size=4096 ./bin/www

Nodejs Auth JWT Passport

 Nodejs Auth JWT Passport ref:  Nodejs Auth JWT Passport สร้าง Project express --view=ejs [[projectName]] a b c

Nodejs Basic Web App Project

Nodejs version list ติดตั้ง Nodejs ด้วย NVM (Node Version Manager) สร้าง Folder สำหรับเก็บ Project mkdir [[projectName]] cd [[projectName]] ตั้งค่า Node Version ผ่าน NVM nvm list   >> check node version nvm install [[node version]]   >> ติดตั้ง node version ที่ต้องการ หรือ ใช้ nvm install --lts เพื่อลง node version ล่าสุด nvm use [[node version]]   >> เลือก node version ที่ต้องการใช้ nvm alias [[alias name]] [[node version]]  >> คำสั่งนี้จะเป็นการสร้าง alias ให้กับ node ของเรา เวลาใช้  nvm use [[projectName]] node -v >> check node version npm -v >> check npm version node - > .nvmrc >> เพื่อสร้างไฟล์ .nvmrc ทำให้เรารู้ว่าโปรเจ็คนั้นใช้ node version อะไร เริ่มสร้าง Nodejs Project  โดยใช้ express-generator npm init –y  >> สร้างไฟล์ package.json กรณีไม่ใช้ express-generator npm install express-generator -g >>  ติดตั้ง express-generator (ตั้งแต่ Node.js 8.2.0 มีมาให้แล้วไม่ต้องทำขั้นตอนน...

NVM (Node Version Manager)

 NVM (Node Version Manager): จัดการกับเวอร์ชันของ node ในเครื่องเรา ref: https://github.com/nvm-sh/nvm#nvmrc ref:  https://www.youtube.com/watch?v=sDkOfY7LBLY วิธีติดตั้ง NVM  ติดตั้ง curl sudo apt-get install curl  ติดตั้ง curl curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash คำสั่งพื้นฐานของ nvm nvm ls คำสั่งนี้จะเป็นการแสดงเวอร์ชันของ node.js ที่เราดาวน์โหลดลงมาในเครื่องแล้ว nvm ls-remote คำสั่งนี้เป็นการแสดงเวอร์ชัน node.js ออกมาทางหน้าจอ การแสดงผลทั้งหมดจะนานหน่อย เลขต่าง ๆ ที่แสดงออกมาทางหน้าจอคือเวอร์ชันที่เราสามารถดาวน์โหลดได้โดยใช้คำสั่ง nvm install <version> nvm install <node version>  คำสั่งนี้จะเป็นดาวน์โหลด node และ dependencies ต่าง ๆ จากอินเทอร์เน็ตลงมาสู่เครื่องของเรา โดยเลขเวอร์ชันที่สามารถดาวน์โหลดได้จะมาจากคำสั่ง nvm ls-remote นั่นเอง nvm install v10.15.0 หมายความว่าให้ดาวน์โหลด node js v10.15.0 มาลงเครื่อง ข้อดีของ...