Links

How to create a VM with NodeJS and node_modules

This is an example we used for an internal project

Build the JS

$ cd project
$ docker run --rm -ti -v $(pwd):/opt/project node bash
​
# cd /opt/project
# npm i
# npm run build

Setup to run in a VM

$ cp .env.defaults dist/
$ cat >> run.sh << EOF
​
#!/bin/sh
​
cd /opt
ls
node /opt/index.js
EOF

Upload the node_modules

$ mksquashfs node_modules node_modules.squashfs
$ aleph file upload node_modules.squashfs
And obtain the item_hash for the next step.

Build and upload the program

$ aleph program create ../my-project/project/dist/ "run.sh"
Add volume ? [y/N] y
Description: node_modules
Mount: /opt/node_modules
Persist on VM host ? [y/N]
Ref: WWW
Use latest version ? [Y/n]
​
Add volume ? [y/N] y
Description: data
Mount: /data
Persist on VM host ? [y/N] y
Volume name: data
Size in MiB: 1000
​
Add volume ? [y/N]
Your program has been uploaded on Aleph .
​
Available on:
https://aleph.sh/vm/XXX
https://yyy.aleph.sh
Visualise on:
https://explorer.aleph.im/address/ETH/ZZZ/message/PROGRAM/XXX
​