Watcher for NodeJS
Learn how to configure Watcher for NodeJS for use with Filebase.
Last updated
Learn how to configure Watcher for NodeJS for use with Filebase.
Last updated
Watcher for NodeJS are modules or tools that allow developers to monitor changes in files or directories and execute code in response to those changes.
NodeJS provides a built-in module called "fs" (file system) that allows developers to interact with the file system. Watchers for NodeJS use the "fs" module to monitor changes in files or directories by continuously checking for modifications, deletions, and additions.
Read below to learn how to use Watcher for NodeJS with Filebase.
To do this, navigate to console.filebase.com. If you don’t have an account already, sign up, then log in.
Select ‘Create Bucket’ in the top right corner to create a new bucket.
Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.
Set up a credentials file for S3FS at ${HOME}/.passwd-s3fs
. You will need to save your Filebase Access and Secret keys to this file and give it owner permissions. You can do so with the following commands:
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs
chmod 600 ${HOME}/.passwd-s3fs
ACCESS_KEY_ID is your Filebase Access key, and SECRET_ACCESS_KEY is your Filebase Secret key. For more information on Filebase access keys, see here.
You can mount a Filebase IPFS bucket with the command:
s3fs mybucket /path/to/mountpoint -o passwd_file=${HOME}/.passwd-s3fs -o url=https://s3.filebase.com
mybucket: name of your Filebase bucket
npm install chokidar fs-extra
observer.js
.Insert the following code into this file:
server.js
that contains the following code:Replace /path/to/watch
with the file path of your mounted Filebase bucket.
node src/server.js
The move will be logged by the watcher script:
[2/21/2023, 11:01:51 AM] Watching for folder changes on: /Users/jessiemongeon/filebase-bucket
[2/21/2023, 11:01:51 AM] /Users/jessiemongeon/filebase-bucket/image.png has been added.