This is the subject of the "5 Minute Backend with Node and Syncano" Lightning Talk presented by Todd Wacker
To complete the exercise, follow the steps below:
- Sign up for a Syncano Account.
- Clone this repo:
git clone https://github.com/syncano-community/syncano-fullstackcon.git
- Point your browser to the
index.html
file included in the repo. - In another tab, navigate to your Syncano Dashboard.
- Create a new Syncano Instance and give it whatever name you want.
- Copy your Syncano Account Key by clicking on the profile picture at the top right corner of your Syncano Dashboard and selecting "Copy Account Key".
- Go to the tab with your
index.html
file open and click "Link Account". Paste your Account Key into the space provided and enter your Instance Name. Submit to link your account. - In your Syncano Dashboard, create a new class called
news_item
. For the schema, give it atitle
(string),url
(string), andupvotes
(integer). - Create 3 News Item Data Objects either in your Syncano Dashboard or by selecting the "Add a News Item" link in your
index.html
file. - Upvote some of the News Items. Notice how the order changes accordingly.
- Create another News Item titled
should delete
and give it whatever url you want. Don't upvote it. - Navigate back to your Syncano Dashboard and create a new Script by selecting "Scripts" in the left nav. Label the Script
news_item_clean_up
and selectNodeJS (latest v 1.0)
as the runtime. - Copy the following code and paste it into the code editor:
var Syncano = require('syncano'); var connection = Syncano({accountKey: CONFIG.accountKey}); var news_items; connection.DataObject.please().list({instanceName: CONFIG.instanceName, className: CONFIG.className}).then(function(items) { items.forEach(function(item) { if (item.upvotes === 0) { connection.DataObject.please().delete({id: item.id, instanceName: CONFIG.instanceName, className: CONFIG.className}).then(function(){ console.log("Item successfully deleted"); }); } }); });
- Set your CONFIG variables on the right. You will need one for
accountKey
(string),instanceName
(string), andclassName
(string). Fill in youraccountKey
andinstanceName
and use "news_item" for theclassName
. Click the blue "Save" button at the top. - Click the blue "Run" button at the top.
- Navigate back to your
index.html
file. The "should delete" News Item should be gone. - Read more about what Syncano can do in the docs.