บทความ

NextJS 14 RestAPI CRUD Prisma

 NextJS 14 RestAPI CRUD Prisma ref: https://nextjs.org/docs/getting-started/installation

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 มาลงเครื่อง ข้อดีของ...

"html-pdf: Failed to load PhantomJS module.

รูปภาพ
วิธีแก้ไขเอาขึ้น server linux แล้ว "error  phantomjs-prebuilt" 1. ลบ lib:  phantomjs-prebuilt ด้วยคำสั่ง   rm -rf node_modules/phantomjs-prebuilt 2.ติดตั้งใหม่ ด้วยคำสั่ง  npm install phantomjs-prebuilt --------------------------------------------- ref: https://github.com/marcbachmann/node-html-pdf/issues/437 ref: https://github.com/marcbachmann/node-html-pdf/issues/212 ref: https://www.javascripttutorial.net/nodejs-tutorial/npm-list/   Copy link ganeshmogare commented on Jun 4, 2018 hi ,i'm trying to use html-pdf module , but it throws "html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath" error , steps i tried to resolve : 1. ...

node js create excel file with xlsx

node js create excel file with xlsx > npm xlsx i ref>>  https://github.com/SheetJS/sheetjs/tree/master/demos/server https://sheetjs.com/demo/manifest.html https://github.com/SheetJS/sheetjs#utility-functions https://github.com/SheetJS/sheetjs#writing-options           var  fileName  =   " 555.xlsx "          var  datas  =   [[ 1 ,   2 ,   3 ],   [ true ,   false ,   null ,   " sheetjs " ],   [ " foo " ,   " bar " ,   new   Date ( " 2014-02-19T14:30Z " ),   " 0.3 " ],   [ " baz " ,   null ,   " qux " ]]          var  wsName  =   " SheetJS "          // console.log(data)          /* generate workbook */          var ...

A way to specify date formating when using XLSX.utils.sheet_to_row_object_array()

Note: these changes are in the repo and will appear in version 0.9.5. If you read in with  cellDates:true , the date-stored-as-number cells will be proper dates. If you set the  dateNF  key of the options object to a number format string, the formatter will use it. Following the example from  my previous comment : > var wb = XLSX . readFile ( ' write.xlsx ' , {cellDates : true }); > wb . Sheets . SheetJS . C3 { t : ' d ' , v : 2014 - 02 - 19T14 : 30 : 00 . 000Z , w : ' 2/19/14 ' } // <-- note: v is a date object > delete wb . Sheets . SheetJS . C3 . w true > XLSX . utils . format_cell ( wb . Sheets . SheetJS . C3 ); ' 2/19/14 ' < -- defaults to the number format code 14 > delete wb . Sheets . SheetJS . C3 . w true > XLSX . utils . format_cell ( wb . Sheets . SheetJS . C3 , null , {dateNF : " YYYY-MM-DD " }); ' 2014-02-19 ' < -- uses the override ref:  https://github.com/Sheet...

การออกแบบ RESTful API - วิธีปฏิบัติที่ดี

เว็บไซต์ใหญ่ๆ ทั้งหลาย อย่างเช่น Google, Facebook, Twitter หรือ ​ LINE ก็ได้เปิดเผย API ออกมาให้ Developer อย่างเราได้เขียนโปรแกรมเพื่อเชื่อมต่อกับบริการของผู้ให้บริการต่างๆ ของเว็บไซต์เหล่านั้น แม้ว่าเราไม่ต้องเขียน API ให้ Developer ได้ใช้ แต่ก็เป็นการดีถ้าแอพพลิเคชันของเรามี API สวยๆ ไว้เผื่อให้อนาคตอาจจะมีเหล่า Developer มาใช้งานบ้าง มีการถกเถียงมากมายในอินเตอร์เน็ตว่า  วิธีไหนเป็นวิธีการที่ดีที่สุด  ในการออกแบบ API โดยที่ไม่มีแนวทางออกแบบอย่างเป็นทางการ และบทความนี้ก็เป็นหนึ่งวิธีที่เหมาะสมอย่างยิ่ง หรือเป็นวิธีปฏิบัติที่ดี A PI ก็ย่อมาจาก  Application Programming Interface  เป็นส่วน interface ที่เชื่อมแอพพลิเคชันกับภายนอก และใช้โดย ​Developer เพื่อใช้ข้อมูลและเข้าถึงข้อมูล ดังนั้นการออกแบบ API ที่ดีจะทำให้ใช้งานได้ง่าย ซึ่งจะทำให้ชีวิต Developer ราบรื่นขึ้น โดยที่ API เปรียบเสมือน GUI สำหรับ Developer ถ้ามันใช้ยุ่งยาก Developer ก็หาวิธีอื่นในการใช้งานหรือเลิกใช้งานไปเลย ดังนั้นประสบการณ์ของ Developer เป็นตัวสำคัญที่จะวัด คุณภาพ ของ RESTful API API เห...