LinuxFoundationX LFW111x - Introduction to Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
/1-mock-static-server
/static
/app.js
/index.html
npm install -g serve
cd 1-mock-static-server/
serve -p 5050 static
/2-mock-zero-dependency
/server.js
/static
/app.js
/index.html
cd 2-mock-zero-dependency/
node server.js
The frontend application starting with serve
cd 2-mock-zero-dependency/
serve -p 5050 static
/3-mock-fastify
/mock-srv
(scaffolding create with `npm init fastify`)
/static
/app.js
/index.html
cd 3-mock-fastify/mock-srv
npm install
cd 3-mock-fastify/mock-srv
npm start
The frontend application starting with serve
cd 3-mock-fastify/
serve -p 5050 static
the key concept is Web Socket
/4-realtime
/mock-srv
(scaffolding create with `npm init fastify`)
/static
/app.js
/index.html
cd 4-realtime/mock-srv
npm install
cd 4-realtime/mock-srv
npm start
The frontend application starting with serve
cd 4-realtime/
serve -p 5050 static
testing from terminal
node -e "http.request('http://localhost:3000/orders/A1', { method: 'POST', headers: {'content-type': 'application/json'}}, (res) => res.pipe(process.stdout)).end(JSON.stringify({amount: 10}))"
the frontend application retrieve the updated data for the order A1
Create a CLI tool to send request to the server and update the order
/5-cli-tool
/mock-srv
(scaffolding create with `npm init fastify`)
/static
/app.js
/index.html
cd 5-cli
npm link
To use the CLI you need started the server and the frontend application as described in the previous sections. Next you can try the cli to automate the update of the order.
5-cli <id> <amount>
# Example
5-cli A1 10