顯示具有 Nodejs 標籤的文章。 顯示所有文章
顯示具有 Nodejs 標籤的文章。 顯示所有文章

2022年12月31日 星期六

Typescript beginning with ts-node

Install nvm first


curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

Example of install nvm

~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15916  100 15916    0     0  32283      0 --:--:-- --:--:-- --:--:-- 32283
=> Downloading nvm from git to '/home/ci/.nvm'
=> Cloning into '/home/ci/.nvm'...
remote: Enumerating objects: 358, done.
remote: Counting objects: 100% (358/358), done.
remote: Compressing objects: 100% (304/304), done.
remote: Total 358 (delta 41), reused 164 (delta 28), pack-reused 0
Receiving objects: 100% (358/358), 218.72 KiB | 1.40 MiB/s, done.
Resolving deltas: 100% (41/41), done.
* (HEAD detached at FETCH_HEAD)
  master
=> Compressing and cleaning up git repository

=> Appending nvm source string to /home/ci/.bashrc
=> Appending bash_completion source string to /home/ci/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Install and select Node.js version by nvm command line

nvm install v18

Please logout and login again to activate nvm.sh shell environment

~$ nvm ls
            N/A
iojs -> N/A (default)
node -> stable (-> N/A) (default)
unstable -> N/A (default)
~$ nvm install v18
Downloading and installing node v18.12.1...
Downloading https://nodejs.org/dist/v18.12.1/node-v18.12.1-linux-x64.tar.xz...
################################################################################################################################ 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.12.1 (npm v8.19.2)
Creating default alias: default -> v18 (-> v18.12.1)
~$ nvm ls
->     v18.12.1
default -> v18 (-> v18.12.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.12.1) (default)
stable -> 18.12 (-> v18.12.1) (default)
lts/* -> lts/hydrogen (-> v18.12.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.2 (-> N/A)
lts/gallium -> v16.19.0 (-> N/A)
lts/hydrogen -> v18.1

Install typescript


~$ npm install -g typescript

added 1 package, and audited 2 packages in 2s

found 0 vulnerabilities
npm notice
npm notice New major version of npm available! 8.19.2 -> 9.2.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.2.0
npm notice Run npm install -g npm@9.2.0 to update!
npm notice

install typescript with specific version

npm install -g typescript@4.6.4

Example of hello.ts


Create example hello.ts file

cat << EOF >> hello.ts
var name:string = "Coder of Typescript";
console.log(`Hello, ${name}`);
EOF

Results of hello.ts

~$ ts-node hello.ts
Hello, Coder

Conclusions

I considere that typescript is a good tool for nodejs to write more stable code. Enjoy The journal for Typescript writing!



2012年2月26日 星期日

用BeagleBone Rev.A3 打造簡易行動NAS系統

承上篇開發環境 BeagleBone A8 實測Linaro-nano, 筆者便想這塊Beaglebone 可以做什麼實際用途呢?

去年,曾寫過試用FreeNas 8.01一文,若能將常用的功能(rsync, ssh, cifs) 放到Beaglebone,則它便可成為一台行動網路NAS。

但FreeNas 還沒有ARM的版本,所以筆者用Linaro-nano 為基礎,作了簡單實做。

開發時,遇到網路卡會不定時自動斷掉,十分惱人。原本以為是Linaro 所用的kernel 不穩定;
後來找了很久,最後發現BeagleBone - Rev. A3上已知硬體問題

Etherent Drop/Reset switch(A3 and A4 Only]
On some A3 and A4 boards, the reset switch can develop a low impedance path to ground creating a voltage divider making the reset line go to 1.5V to 1.8V. To determine this you can measure the voltage on pin 10 of P9. This issue can cause intermittent resets of the SMSC PHY, causing the link to drop. To fix this, just remove the reset switch. No, it will not void the warranty on the board if you remove the reset switch. You can request an RMA for a new switch and one will be sent to you. You can also request an RMA, return the board, and we will repair the switch for you.

remove_reset_button

依照說明(不會因此破壞保固),用尖嘴鉗把Reset 按鈕暴力拔除;斷電後,重新啟動執行,測試超過24小時,目前都運作正常。


簡易NAS移植

在Linaro 中,以apt-get 安裝下列套件
  • CIFS - Samba
  • Rsync -
  • FTP  - sftp
  • SSH - openssl-server
另外,使用者介面部分,暫時先以編輯設定檔方式來修改啟動必要之功能。

目前在開發板中,以Web方式來實作必要的管理介面。
Web 由將下列主要由 node.js+ python batchjob 組成。

利用node.js來實做web 介來顯示系統狀態:

使用arm gcc-4.6.1, 編譯node.js 0.6.9,並安裝npm套件: express, commander, nconf

NAS Web Prototype – Status

nas-web

小結:

經由上述實做,筆者將beaglebone Rev.A3 打造成為一個小型NAS 系統,
可利用 rsync , ssh/sftp , cifs 來經由網路存取其SD卡或姆指碟,
而系統記憶使用量約在80MB左右,應可進一步瘦身;
最後可依筆者需求來開發對應Restful API來進行管理作業。