Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9013

50行でちゃんと動くリマインダーアプリ「Notification-CLI」をリリースしました

$
0
0

50行でちゃんと動くリマインダーアプリ「Notification-CLI」をリリースしました

以下かんたんな日本語版クイックスタートになります。

Minimalistic Command Line Notification Application under 50 Lines

50行で実装のシンプルなコマンドラインベースのリマインダーアプリケーション。

クイックスタート Quick Start

This will nofity you when 2021 February 20, PM 6:00.

以下で2021年2月20日18時に通知をします。

./noc.js -d 2021022018 --desktop

Very much minimalistic.

とてもミニマリスティック。

インストール Installation

git clone https://github.com/yuis-ice/notification-cli.git
cd notification-cli
chmod 755 ./noc.js
npm i

必要環境 Requirements

  • node.js v13.10.1 or higher
# node.js [nvm-sh/nvm](https://github.com/nvm-sh/nvm)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
bash
nvm install v13.10.1
node -v

使用例 Examples

This will only notify you by command line console output:

コマンドライン出力で通知します。

./noc.js -d 2021022018

The output be like:

出力はこんな感じです。

$ ./noc.js -d 202102120234
2021-02-12T02:33:16+09:00 Jobs started...
2021-02-12T02:33:16+09:00 You will be notified at: 2021-02-12T02:34:00+09:00
2021-02-12T02:34:00+09:00 Notified.
$

You can abbreviate your seconds, minutes, hours and so on:

秒、分などを省略しても動きます。

./noc.js -d 2022

This will notify you when PM 11:00 in the day:

その日の23時になったら通知します。

./noc.js -d 23 --format HH

An alias makes your code much more minimalistic:

エイリアスを定義すると、よりシンプルになります。

alias notify="./noc.js --format MM,DD,HH" # Specifying absolute path recommended
notify -d 2,20,18

This will run your command:

シェルコマンド、外部コマンドも実行できます。

./noc.js -d 2021022018 -c "firefox.exe sound.mp3"

No logs on background be like:

バックグラウンドでマルチインスタンスに使用するのもいいですね。

./noc.js -d 2021022018 --desktop --hide-log --log "" &

My favorite format <3

僕のお気に入り。

./noc.js -d 2021022018 -c "firefox.exe sound.mp3" --desktop -t "your appointment soon"

コマンドラインオプション Command line Options

$ ./noc.js
Usage: notification-cli [options]

Options:
  -d, --date <date>             specify date to fire (e.g. "2022010100" for 2020/1/1 00:00) (default: null)     
  -f, --format <format>         specify date format (default: "YYYYMMDDHHmmss")
  -D, --desktop                 enables desktop notification
  -t, --title <text>            specify title (default: "Notification-CLI")
  -m, --message <text>          specify message (default: ":)")
  -c, --exec-command <command>  specify command to run (e.g. firefox.exe ringtone.mp3) (default: null)
  -l, --log <text>              specify console log message (default: "Notified.")
  -H, --hide-log                hide infomation logs
  -h, --help                    display help for command

一言

コードを書くよりreadmeを書く時間のほうが長くなってしまった例。

momentjsとnode-scheduleのおかげでimportやコマンドラインオプション部分を除くメインのコードはなんと10行程度で収まっています。

ソースコードを見られたら少し恥ずかしいかもしれない。対してソースコードのシンプリシティは初学者にとってそのコードを研究する敷居を低くしてくれると思うので、node.jsあるいはプログラミング初学者の人に積極的に参考にして頂ければ嬉しいと思う。


Viewing all articles
Browse latest Browse all 9013

Trending Articles