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


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Directus
  3. Directus 9 : sample NodeJS scripts?

Directus 9 : sample NodeJS scripts?

Scheduled Pinned Locked Moved Directus
5 Posts 3 Posters 1.2k Views 5 Watching
  • 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.
  • timconsidineT Offline
    timconsidineT Offline
    timconsidine
    App Dev
    wrote on last edited by timconsidine
    #1

    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 ?

    robiR 1 Reply Last reply
    0
    • timconsidineT 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 ?

      robiR Offline
      robiR Offline
      robi
      wrote on last edited by
      #2

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

      Conscious tech

      timconsidineT 1 Reply Last reply
      0
      • robiR robi

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

        timconsidineT Offline
        timconsidineT Offline
        timconsidine
        App Dev
        wrote on last edited by
        #3

        @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.

        robiR ? 2 Replies Last reply
        0
        • timconsidineT timconsidine

          @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.

          robiR Offline
          robiR Offline
          robi
          wrote on last edited by
          #4

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

          Conscious tech

          1 Reply Last reply
          0
          • timconsidineT timconsidine

            @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.

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @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
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Bookmarks
            • Search