JSBox Node module issues

I was wondering if there was enough in interest in JSBox to have a thread dedicated to it? If we did, perhaps we could get the author to join in. JSBox seems to be analogous to Pythonista (except of course that it uses Javascript). Like Scriptable one can create widgets and there is Shortcut action support. I think Scriptable is also an excellent app for JS but it uses the Browser view whereas JSBox uses node.js. Both have their strengths. There is a JSBox forum but it is entirely in Chinese.

1 Like

Could you please post a bit more about the individual strengths of JSBox and Scriptable?

(I tend to use Scriptable, but probably partially due to lack of knowledge about JSBox)

I am definitely not the authority on JSBox (nor do I have any vested interest) but I have found that there are times when the fact that Scriptable uses the JS for the Browser vs. Node.js (which is for server-side programs) can be limiting. I would recommend trying it out (https://apps.apple.com/us/app/jsbox-learn-to-code/id1312014438). I will say that it is not free and the “trial” version gives you barely enough time to test it thoroughly but it does seem to be rather feature-rich. I think that most of its users must be native Chinese (as is the author) since the only online forum I found is entirely in Chinese.

As JSBox uses node.js, I tried the following script which works fine as is using node on MacOS. Under JSBox it gives the error:
TypeError: express is not a function. (In ‘express()’, ‘express’ is an instance of Object)
line 2, column 18
Can anyone tell what is going on? Bug in JSBox?

var express = require('express');
var app = express();

app.get('/', function (req, res) {
   
    var sql = require("mssql");

    // config for your database
    var config = {
        user: 'user',
        password: 'pswd',
        server: 'host', 
        database: 'dbname' 
    };

    // connect to your database
    sql.connect(config, function (err) {
    
        if (err) console.log(err);

        // create Request object
        var request = new sql.Request();
           
        // query to the database and get the records
        request.query('select * from tablename', function (err, recordset) {
            
            if (err) console.log(err)

            // send records as a response
            res.send(recordset);
            
        });
    });
});

var server = app.listen(5000, function () {
    console.log('Server is running..');
});

I don’t know JSBox but maybe it doesn’t include express.

(It’s been a long while since I did anything with node so maybe it is expected to come with express built in. But I doubt it.)

I added express and MSSQL from within JSBox and they show as being there.

Not sure if it has anything at all to do with the error I am seeing but if I go to Resolve Dependencies under node.js modules in jsbox, I get:

Dependencies: mssql@^6.2.1, express@^4.17.1, moment@^2.27.0

(node:11126) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead.

  • mssql@6.2.1
  • express@4.17.1
  • moment@2.27.0
    updated 3 packages and audited 135 packages in 8.885s
    found 0 vulnerabilities

It seems to have resolved dependencies but each time I go to this option they reappear. I will note that the moment modules works fine (var moment = require(‘moment’); ) but mssql and express throw an error as described above. As previously noted, this script works fine on a mac with node.

Can anyone please help me to get this working?

Express works fine but you can’t use modules that have native dependencies (or node-gyp c or c++) stuff. I would assume (without looking) that the MySQL client is not a pure js lib.

But the error (TypeError: express is not a function. (In ‘express()’, ‘express’ is an instance of Object)
line 2, column 18) is pointing at express, no?

1 Like

give this a whirl:

const express = require("express");
const safari = require("safari");
const app = express();
const port = 3000;
const url = `http://127.0.0.1:${port}`;

app.get("/", (req, res) => {
  res.send("<h1>Hello World!</h1>");
});

app.listen(port, () => {
  safari.open(url);
});

Tried it and got:


TypeError: express is not a function. (In 'express()', 'express' is an instance of Object)

line 3, column 20

stack => file:///private/var/mobile/Containers/Shared/AppGroup/5788CBDF-F40B-4B60-A716-56BD8B011D51/JSBox/Code/Express_test.js:5:20
asyncFunctionResume@[native code]
__jsbox__aba9b405088d9158add49ca70f11ee0c@file:///private/var/mobile/Containers/Shared/AppGroup/5788CBDF-F40B-4B60-A716-56BD8B011D51/JSBox/Code/Express_test.js:1:58

With the kind help of the author of JSBox, I now have this working. The problem was that it is not enough to simply enter the script by itself. I needed to run the script inside a node package. I can now confirm that JSBox will communicate with a MS SQL server.

Okay I’m extremely new to app and web coding. I’m using js box pro- can’t find a whole lot of support for[quote=“ihf, post:1, topic:7905, full:true”]
I was wondering if there was enough in interest in JSBox to have a thread dedicated to it? If we did, perhaps we could get the author to join in. JSBox seems to be analogous to Pythonista (except of course that it uses Javascript). Like Scriptable one can create widgets and there is Shortcut action support. I think Scriptable is also an excellent app for JS but it uses the Browser view whereas JSBox uses node.js. Both have their strengths. There is a JSBox forum but it is entirely in Chinese.
[/quote]

it. I also use scriptable and shortcuts and shortcuts pro. Okay I’m relatively new to app and web coding. I’m using js box pro- can’t find a whole lot of support for it. I also use scriptable and shortcuts and shortcuts pro. I have an iPhone 13 pro that is running the latest software (iOS 15.2) and since I had the iPhone 11 Pro a lot of the shortcuts throw errors or don’t work correctly. I’ve managed to create a few modules …

I found a few scripts online (one actually on this thread. To run the script ‘hello world!’ To begin with the original script it was telling me there was an error because of ‘!’ So I tried one of the above script.

Any ideas or suggestions?

———————————

const express = require(“express”);
const safari = require(“safari”);
const app = express();
const port = 3000;
const url = http://127.0.0.1:${port};

app.get(“/”, (req, res) => {
res.send(“

Hello World!

”);
});

app.listen(port, () => {
safari.open(url);
});

———Below is the result…———

TypeError: express is not a function. (In ‘express()’, ‘express’ is an instance of Object)

line 7, column 20

const app = express();
const port = 3000;
const url = http://127.0.0.1:${port};

stack => @
asyncFunctionResume@[native code]
__jsbox__fde3fc98615cf43fe28c67dba09926a2@