Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Node.js support

    I using SmartClient Pro 13.0 and I'm trying to use it with Node.js
    But when I'm following the instructions

    $ npm init

    $ npm install -S smartclient-node
    npm WARN deprecated natives@1.1.6: This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs@4.x.
    npm WARN deprecated multer@1.4.4: Multer 1.x is affected by CVE-2022-24434. This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10.
    npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
    npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
    npm WARN cleanup Failed to remove some directories [
    npm WARN cleanup [
    npm WARN cleanup 'C:\\xxx\\my-app\\node_modules\\dtrace-provider',
    npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'C:\xxx\my-app\node_modules\dtrace-provider'] {
    npm WARN cleanup errno: -4082,
    npm WARN cleanup code: 'EBUSY',
    npm WARN cleanup syscall: 'rmdir',
    npm WARN cleanup path: 'C:\\xxx\\my-app\\node_modules\\dtrace-provider'
    npm WARN cleanup }
    npm WARN cleanup ],
    npm WARN cleanup [
    npm WARN cleanup 'C:\\xxx\\my-app\\node_modules',
    npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'C:\xxx\my-app\node_modules\dtrace-provider'] {
    npm WARN cleanup errno: -4082,
    npm WARN cleanup code: 'EBUSY',
    npm WARN cleanup syscall: 'rmdir',
    npm WARN cleanup path: 'C:\\xxx\\my-app\\node_modules\\dtrace-provider'
    npm WARN cleanup }
    npm WARN cleanup ]
    npm WARN cleanup ]
    npm ERR! code 1
    npm ERR! path C:\xxx\my-app\node_modules\smartclient-node
    npm ERR! command failed
    npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node install.js
    npm ERR! fs.js:42
    npm ERR! } = primordials;
    npm ERR! ^
    npm ERR!
    npm ERR! ReferenceError: primordials is not defined
    npm ERR! at fs.js:42:5
    npm ERR! at req_ (C:\xxx\my-app\node_modules\natives\index.js:143:24)
    npm ERR! at Object.req [as require] (C:\xxx\my-app\node_modules\natives\index.js:55:10)
    npm ERR! at Object.<anonymous> (C:\xxx\my-app\node_modules\fstream\node_modules\graceful-fs\fs.js:1:37)
    npm ERR! at Module._compile (node:internal/modules/cjs/loader:1254:14)
    npm ERR! at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    npm ERR! at Module.load (node:internal/modules/cjs/loader:1117:32)
    npm ERR! at Module._load (node:internal/modules/cjs/loader:958:12)
    npm ERR! at Module.require (node:internal/modules/cjs/loader:1141:19)
    npm ERR! at require (node:internal/modules/cjs/helpers:110:18)
    npm ERR!
    npm ERR! Node.js v18.14.2

    The only way I can make the installation work is if I create a React app

    $ npx create-react-app my-app

    $ npm install smartclient-pro --username=... --password=...

    Is that the way it is supposed to work? If yes, can you please provide a complete example exactly where in the React-code to put the smartclient-components?

    #2
    Hi there, could you clarify what you're trying to do?

    1. are you trying to use a SmartClient frontend with a Node.js backend (where Node.js is used for persistence, for example to a database)

    .. or ..

    2. are you trying to use SmartClient via React to build a UI (covered here: https://smartclient.com/smartclient-.....reactSupport)

    .. or ..

    3. are you maybe just trying to use npm (Node Package Manager) as a means of installing SmartClient?

    If it's #2 or #3, what are you planning as far as server technology - Node, Java, .NET? Are you planning to use our sample server code or just start from our pre-built REST protocols?

    Comment


      #3
      Hi,
      I'm trying option #1. The reason is that I want the backend to have a REST-api that can be called by other processes than the GUI (SmartClient widgets). And this is because of we are building a machine-to-machine integration as well as a human interface. I'm using NodeJS as a server technology since I find it easier to use and less boilerplate than Tomcat / Spring Boot.
      So for the time being I've written a work-around to manually do a XHTTP request from the JavaScript code but it would be great to be able to use the DataSource save/update/delete etc. if that is possible.

      Comment


        #4
        As far as your current approach, you definitely want to be using DataSources. You should pause the road you've started on and take a look at the QuickStart Guide, focusing on Data Integration. There is a complete, pre-built, client-server REST protocol that gives you everything you need when connecting data-aware components to any kind of server.

        Not only have you started down the road of reinventing an absolutely colossal wheel, but your approach is also doomed to fail, because you are going to be looking for APIs and override points that are designed into the DataSource system, and not finding them, because they are designed into the DataSource system.

        As far as your overall goal, if you are open to commercial solutions, the best approach by far is to use the SmartClient Server. With a single line of .ds.xml, you can have an OpenAPI described REST service connected to a pre-existing database table, as well as instant full-CRUD integration with all of SmartClient's client-side components.

        So, that gives you everything you've described requiring, right out of the box, with zero boilerplate.

        If you prefer instead to implement all of that yourself, you can use whatever backend you like, but on the front-end you would generally want to use RESTDataSource. The QuickStart Guide chapter on Data Integration is again the place to start.

        Comment


          #5
          By defining this in my index.js I succeed to send in values properly

          var deviceDS = isc.RestDataSource.create({
          ID:"deviceDS",
          fields:[ {
          ...
          }],
          fetchDataURL:"/device/fetch",
          addDataURL:"/device/add",
          updateDataURL:"/device/update",
          removeDataURL:"/device/remove" });

          The way I send it in is through
          myDynamicForm.saveData()

          I have used ds.xml-files before and I find them vey useful. That was when the server was a Tomcat/SpingBoot.
          But is is also possible when the server is NodeJS?
          Last edited by GraphUser; 28 Feb 2023, 02:13.

          Comment


            #6
            It's sort-of possible to use .ds.xml in a Node.js server. smartclient-node had that feature, but it was created by an independent developer (we were just promoting it for him) and it appears to have bitrotted.

            We do plan to take a look at smartclient-node and see if it's easy to make it work again. It could be that all it needs are minor configuration updates, or it could be one of those situations where it uses libraries that were changed radically without backcompat. Also, we have a lot going on at the moment, so it's going to take a while to get to this.

            If you're excited to use .ds.xml files with Node.js, we'd definitely appreciate anything you might contribute regarding smartclient-node!

            However, note that while smartclient-node uses .ds.xml files for configuration, it only has a tiny fraction of the Java server's features. Just to name a few:

            - no validators
            - no custom (non-SQL-CRUD) operations
            - no Declarative Security
            - no exports
            - no SQL templating
            - no OpenAPI support

            .. this list could go on for literally pages.

            So, in sum,

            1. the Java-based SmartClient Server gets you what you want instantly

            2. smartclient-node would give you some pieces of what you want, if you're willing to try to figure out the bitrot!

            Comment


              #7
              Ok. Thanks for your help!

              Comment

              Working...
              X