Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


    Cloudron Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular

    Directus 9 : sample NodeJS scripts?

    Directus
    3
    5
    389
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • timconsidine
      timconsidine App Dev last edited by timconsidine

      I'm developing a small app for a society.
      Currently favouring Budibase because it has front-end and back-end and app designer.
      But keen to explore how Directus could handle the same project.

      Installed custom Directus 9 as a Cloudron app (thanks to @atrilahiji)
      I'll think about front-end for Directus app later.
      Fo now I want to prove out the storing and retrieval of data in/from Directus.

      But not finding any suitable example NodeJS scripts.
      Yes, I have read Directus Docs. But no 'tutorial' for noobs like me.
      Does anyone have any pointers ?

      robi 1 Reply Last reply Reply Quote 0
      • robi
        robi @timconsidine last edited by

        @timconsidine can you describe what you're trying to do, in terms of the app?

        Life of Advanced Technology

        timconsidine 1 Reply Last reply Reply Quote 0
        • timconsidine
          timconsidine App Dev @robi last edited by

          @robi At this stage, I'm just scaffolding a simple command line CRUD script to prove connection to the hosted Directus.

          I've managed to craft a bare-bones script for create and read (in case it helps any other noob).

          import { Directus } from '@directus/sdk';
          const directus = new Directus('https://domain/');
          await directus.auth.static('static_token');
          
          const test = directus.items('test');
          await test.createOne({
              status: 'draft',
              name: 'Jo',
              age: 20,
              points: 5,
          });
          
          const tests = await directus.items('test').readMany();
          console.log({
              items: tests.data,
          //      total: tests.meta.total_count,
          });
          

          The "total: tests.meta.total_count" is straight from web docs, but doesn't work, so investigating. Probably my error as usual.

          So now I know calls to Directus work fairly easy.
          I guess where my knowledge is failing (apart from this being the very first Node script I've done) is linking CRUD functions to a front-end. But I will keep looking.

          The intended app is also v.simple.

          • Users self-register
          • Users login
          • User then views available events
          • User registers for event and buys tickets to event (probably handle that through a Stripe call)
          • Email ticket confirmation and receipt to user
          • User can reset their password

          I guess I will figure out, just always prefer to use a library or framework for the heavy lifting and reduce scope for errors in my DIY coding.

          robi ? 2 Replies Last reply Reply Quote 0
          • robi
            robi @timconsidine last edited by

            @timconsidine ah, let's see what @marcusquinn thinks about that, as he's been using EspoCRM for similar things.

            Life of Advanced Technology

            1 Reply Last reply Reply Quote 0
            • ?
              A Former User @timconsidine last edited by

              @timconsidine ah so you’re working on auth. I haven’t done any auth stuff in there yet but I can give it a shot at some point here. As for that script, idk I haven’t used their SDK ever. My use case involved publicly readable data so I just make a basic get request to there using the axios library

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB