Javascript Modules
Refs
What is a Javascript Module ?
Just a javascript file which can import functionality from other and export its own functionality.
Just a javascript file which can import functionality from other and export its own functionality.
The industry-standard protocol for authorization.
This specification and its extensions are being developed within the IETF OAuth Working Group.
(THIS BLOG IS STILL IN PROGRESS)
A strongly typed programming language that builds on JavaScript.
Smaller, more expressive, more robust.
VS Epxress
The key difference between Koa and Express is how they handle middleware. Express includes routing and templates in the application framework. Koa, on the other hand, requires modules for these features, therefore making it more modular or customizable.
A material-design UI framework for UI.
vue-cli
created project, type vue add vuetify
in project root folder.<el-config-provider>
for configuration to work.<el-config-provider>
will pass to all sub-components. See available propertiesExample:
A thread that enables node.js to execute JavaScript in parallel. Useful to handle CPU intensive jobs.
Create a worker file => Make a promise in caller file => Define on message/error/exit hooks
worker.js file:
1 | const { workerData, parentPort } = require('worker_threads') |
index.js file:
1 | const { Worker } = require('worker_threads') |
Key points:
workerData
to receive data from caller and parentPort
to post data to caller.parentPort.postMessage
to send data to caller and caller use on('message')
to receive.Single threaded node.js will block on a time-consuming request.
Example:
1 | const http = require('http'); |
Call localhost:3000/compute
will block
Pros:
Use child_process.fork
to create new process.
Main.js:
1 | const http = require('http'); |
compute.js:
1 | const computation = () => { |
cluster
can create worker process in a single file.
Example:
1 | const http = require('http'); |
Running code above, we got:
1 | Master process id is 18428, cpu number 4 |
We can find these process in task manager:
Now send a request in browser, and id of one of the four server process is returned:
Try refresh many times and different pids may return(It depends, maybe one unlucky process shoulders all the workload).
Now kill one the worker 1460
in task manger and we got:
1 | worker process died,id 1460 |
Refresh the browser and result is another pid other than 1460:
You see, now our server is much more robust than before. We got four worker process, killing one of them and there are still three working.
Cluster calls the same fork
method from child_process
module under the hood. Cluster is a master-slave model, where master manages and schedules slaves.
Why no Error: EADDRINUSE
when multiple processes listens on the same port?
The child processes aren’t listening to the same port. Incoming socket connections to the master process are being delegated to the child processes. There’s special handling for clustered process in server.listen()
, it calls a method named listenInCluster()
in some circumstances. See explanation here
cluster
worker threads
SharedArrayBuffer
) Using node oracledb
to develop a backend api and encountered NJS-016: buffer is too small for OUT binds
exception for a simple select query: select a, b, c from tab@dblink
NJS-016: buffer is too small for OUT binds
and found little help. None of them suits my case.AMERICAN_AMERICA.AL32UTF8
and for remote database is AMERICAN_AMERICA.ZHS16GBK
. Changed charset environment variable to the same as remote database, still no luck.b
has some weired behavior: for chinese character value 神经阻滞
it only shows first two characters 神经
when environment variable is set to AMERICAN_AMERICA.AL32UTF8
, different from database charset AMERICAN_AMERICA.ZHS16GBK
. Column b
definition is varchar2(8)
. Maybe has something to do with this ?For charset AMERICAN_AMERICA.ZHS16GBK
, each chinese character is 2 bytes wide.
For charset AMERICAN_AMERICA.AL32UTF8
, each chinese character is 3 bytes wide.
With varchar2(8)
, it can hold 4 characters on AMERICAN_AMERICA.ZHS16GBK
, 2 characters on AMERICAN_AMERICA.AL32UTF8
. That’s why it only shows 2 characters when environment variable is AMERICAN_AMERICA.AL32UTF8
.NJS-016
indicates out binds with varhcar2(8)
cannot hold 神经阻滞
as it is 4×3=12 bytes wide.
varchar2(8)
to a at least varchar2(12)
(Intrusive, not recommended).