This tiny script handles the over-the-air update in case you run node.js software in embedded linux system (such as raspberry pi). It takes advantage of NPM capability to install npm module from github (private or public repo) so the setup is super easy and don't require your own back-end server to function. All you have to do is host your node software in a github repo and create a package.json for use.
- Start from a fresh new directory then run the command below.
git clone https://github.com/heartnetkung/npm-ota-update.git
sudo npm install
- Inspect
config.json
file and change it to match your settings. If you are not sure, you can skip to step 3. The given settings will install a dummy repo. To get your token follow this tutorial.
{
/*token is for private repo only*/
"token":"<TOKEN>",
"package_url":"https://api.github.com/repos/<github-user>/<github-repo>/contents/package.json?ref=master",
/*for private repo*/
"npm_install_url":"git+https://<token>:x-oauth-basic@github.com/<github-user>/<github-repo>.git",
/*for public repo*/
"npm_install_url":"<github-user>/<github-repo>",
"main":"app.js"
}
- run the run.sh using
./run.sh
At this step, your code will be downloaded from github. Later on you can run this script again instead of your program and it will automatically update your software in background for you everytime the program starts. The next version will be applied before the next time your pragram start.
- Update config.json together with the program (useful when you rename your repo)
// package.json in your github repo
{
"name": "your-awesome-node-module",
"author": "you <youremail@email.com>",
"version": "1.0.5",
"hnk_updater": {
"token": "<TOKEN>",
"main":"app.js"
/*anything here will replace config.json*/
}
}
- run
./run.sh reset
to delete all program you downloaded and start anew with what you specify in theconfig.json