#node.js

有時候檔案太大,沒有辦法一次整個上傳,比如說影片、圖片等,這時候我們就需要將檔案拆成一小塊一小塊的 bytes 上傳

實作流程:

  • 使用者上傳檔案
  • FileReader 讀取檔案內容
  • 將檔案拆成一小塊一小塊後上傳
  • 後端收到每一小塊資料後 append 到該檔案裡

閱讀更多......

在什麼樣的情況下需要效能提升?

如果我們的程式需要進行重度的計算,而且這個任務無法像 timer, http request 等,可以非同步運行時,我們的 Request 就會被卡住

ex:

const express = require('express');

const app = express();

function doWork(duration) {
const start = Date.now();
while(Date.now() - start < duration) {}
}

app.get('/', (req, res) => {
doWork(5000)
res.send('<h1>Hi There!</h1>');
});

app.listen(3000, () => {});

閱讀更多......

不廢話先上題,請問以下程式 conosole.log 的順序?

const https = require('https');
const crypto = require('crypto');
const fs = require('fs');

const start = Date.now();

function doRequest() {
https
.request('https://www.google.com', res => {
res.on('data', () => {})
res.on('end', () => {
console.log('Request:', Date.now() - start);
})
})
.end();
}

function doHash() {
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => {
console.log('Hash:', Date.now() - start);
})
}


doRequest();

fs.readFile('text.txt', 'utf8', () => {
console.log('FS:', Date.now() - start);
})

doHash();
doHash();
doHash();
doHash();

閱讀更多......

Apollo Server 3 後,將 graphql-playground 改為自家的 apollo-studio, 當你一開啟

http://localhost:{YOUR_DEV_PORT} 時,它會主動導頁到 https://studio.apollographql.com

一開始用的時候,覺得特別好用,apollo-studio 的 auto-complete 的功能比 graphql-playground 好用許多,但是做到登入的功能時遇到這個問題困擾我超久,明明就有給 set-cookie 的 header,但是怎麼樣都拿不到 cookie

閱讀更多......

Express Concept

Express is a bunch of middlewares works together

Expresss Basic Routing

const express = require('express');
const app = express();

app.get('/register', (req, res) => {
const body = req.body;
const isSucceed = auth(body);
if (isSucceed) {
res.send('Register Successfully');
} else {
res.status(443).sene('Authentication fail, unable to register');
}
});

閱讀更多......

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×