Quote from caro on November 9, 2024, 12:14 amI can execute node js functions on my computer offline. (nodejs is installed on my Notebook ).
I run the functions from visual studio code or from command line .
My question is :
1, Is node js supported on Visual Neoweb ?
2, How do i use external library on visual neo web ? How it is defined and used ?
Regards
I can execute node js functions on my computer offline. (nodejs is installed on my Notebook ).
I run the functions from visual studio code or from command line .
My question is :
1, Is node js supported on Visual Neoweb ?
2, How do i use external library on visual neo web ? How it is defined and used ?
Regards

Quote from luishp on November 9, 2024, 12:30 pm@caro you can call any NodeJS script from VisualNEO Web using neoAjax plugin to send and receive JSON or some other data formats.
Another option is compiling for NWjs (Desktop apps). In this case you can use NodeJS code directly within your VisualNEO Web app using BeginJS and EndJS commands. Please check the NWjs section on this forum for more information about this option.
@caro you can call any NodeJS script from VisualNEO Web using neoAjax plugin to send and receive JSON or some other data formats.
Another option is compiling for NWjs (Desktop apps). In this case you can use NodeJS code directly within your VisualNEO Web app using BeginJS and EndJS commands. Please check the NWjs section on this forum for more information about this option.
Quote from caro on November 9, 2024, 6:26 pmMy nodejs code which is Running perfect on Visual Studio even from a command line
const fs = require("fs") const content1= "89075337635954647102216077828334038179638322940664906113645556950358984065099 test1" const content2="890753376359546471022160778283340381796383228179638322940664906113645556950358984065099 test2" const content3="890753376359540381796383229406649061136455569503589840606113645556950358984065099 test3" //File Write1 fs.writeFileSync("content1.txt", content1); //File Write2 fs.writeFileSync("content2.txt", content2); //File Write3 fs.writeFileSync("content3.txt", content3); console.log("Done writing") // passing result to neoscript //$App. dat1 = content1 ;1, Tried Your suggestions to call via ajax as a script file....... (Nothing happens )
2, Compiled it and tested ..... issues on the console code READ AS >> ( ReferenceError: require is not defined )
If Neoweb is a Java script platform why the codes are not Executed as they do on Visual Studio and Command line ?
as far as Nodejs is installed on computer, scripts run literally from anywhere as i understand it , and offline !
even there is a mobile version of nodejs which enables nodejs independant apps to work offline.Please , Examples are appreciated !
Regards
My nodejs code which is Running perfect on Visual Studio even from a command line
const fs = require("fs")
const content1= "89075337635954647102216077828334038179638322940664906113645556950358984065099 test1"
const content2="890753376359546471022160778283340381796383228179638322940664906113645556950358984065099 test2"
const content3="890753376359540381796383229406649061136455569503589840606113645556950358984065099 test3"
//File Write1
fs.writeFileSync("content1.txt", content1);
//File Write2
fs.writeFileSync("content2.txt", content2);
//File Write3
fs.writeFileSync("content3.txt", content3);
console.log("Done writing")
// passing result to neoscript
//$App. dat1 = content1 ;
1, Tried Your suggestions to call via ajax as a script file....... (Nothing happens )
2, Compiled it and tested ..... issues on the console code READ AS >> ( ReferenceError: require is not defined )
If Neoweb is a Java script platform why the codes are not Executed as they do on Visual Studio and Command line ?
as far as Nodejs is installed on computer, scripts run literally from anywhere as i understand it , and offline !
even there is a mobile version of nodejs which enables nodejs independant apps to work offline.
Please , Examples are appreciated !
Regards

Quote from luishp on November 10, 2024, 10:14 am@caro here's how you can communicate with NodeJS step-by-step (note that if you use NWjs you can just use your code directly):
Step 1: Create a Node.js Script
Create a Node.js script that acts as a server and handles HTTP requests. You can use the
expresslibrary to set up a basic server.Example Node.js Script (
server.js):const express = require('express'); const app = express(); const port = 3000; // You can choose any available port // Middleware to parse JSON bodies (optional) app.use(express.json()); // Endpoint to handle AJAX requests app.post('/process-data', (req, res) => { console.log('Received data:', req.body); // Logs incoming data to the console // Process the data as needed const responseData = { message: 'Data processed successfully', data: req.body }; // Send a JSON response res.json(responseData); }); // Start the server app.listen(port, () => { console.log(`Server is running at http://localhost:${port}`); });
Step 2: Run Your Node.js Server
- Save the script above as
server.js.- Install
expressif you haven't already by running (bash):npm install express
Start the server by running (bash):
node server.js
The server will be running at
http://localhost:3000.Step 3: Use
neoAjaxSendExin VisualNEO WebIn VisualNEO Web, use
neoAjaxSendExto make a request to your Node.js server.Example VisualNEO Web Script:
SetVar [url] "http://localhost:3000/process-data" // Ensure the URL matches your Node.js server SetVar [dataToSend] '{"key1":"value1","key2":"value2"}' // JSON string to send as the request body SetVar [headers] "Content-Type: application/json" // Header to indicate JSON format neoAjaxSendEx [url] "POST" [headers] [dataToSend] "json" "handleSuccess" "handleError" .Place this code in handleSuccess subroutine: AlertBox "Success" "Response: [AjaxResponse]" "" Return .Place this code in handleError subroutine: AlertBox "Error" "There was an issue with the request." "" Return
Explanation of the
neoAjaxSendExCommand:
[url]: The endpoint to your Node.js server."POST": The HTTP method for the request (use"GET"if you don't need to send data).[headers]: Headers for the request (e.g.,Content-Type: application/jsonfor JSON data).[dataToSend]: The data payload as a JSON string if needed."json": Specifies the expected response type."handleSuccess": Subroutine for handling successful responses."handleError": Subroutine for handling errors.Step 4: Test the Integration
- Run your Node.js server (
node server.js).- Execute the
neoAjaxLoadrequest in VisualNEO Web by running your project.- Check that your Node.js server receives the request, processes it, and sends a response back to VisualNEO Web.
Additional Tips:
- CORS: If VisualNEO Web and your Node.js server are running on different domains or ports, ensure that CORS (Cross-Origin Resource Sharing) is properly configured in your Node.js app:
const cors = require('cors');
app.use(cors());
- Deployment: For production use, deploy your Node.js app to a cloud service (e.g., Heroku, AWS) or host it on a server with a public-facing IP or domain.
This approach will enable your VisualNEO Web app to communicate with a Node.js backend, allowing for dynamic data processing, interactions with databases, or other server-side operations.
@caro here's how you can communicate with NodeJS step-by-step (note that if you use NWjs you can just use your code directly):
Create a Node.js script that acts as a server and handles HTTP requests. You can use the express library to set up a basic server.
Example Node.js Script (server.js):
const express = require('express');
const app = express();
const port = 3000; // You can choose any available port
// Middleware to parse JSON bodies (optional)
app.use(express.json());
// Endpoint to handle AJAX requests
app.post('/process-data', (req, res) => {
console.log('Received data:', req.body); // Logs incoming data to the console
// Process the data as needed
const responseData = { message: 'Data processed successfully', data: req.body };
// Send a JSON response
res.json(responseData);
});
// Start the server
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});
server.js.express if you haven't already by running (bash):
npm install express
Start the server by running (bash):
node server.js
The server will be running at http://localhost:3000.
neoAjaxSendEx in VisualNEO WebIn VisualNEO Web, use neoAjaxSendEx to make a request to your Node.js server.
Example VisualNEO Web Script:
SetVar [url] "http://localhost:3000/process-data" // Ensure the URL matches your Node.js server
SetVar [dataToSend] '{"key1":"value1","key2":"value2"}' // JSON string to send as the request body
SetVar [headers] "Content-Type: application/json" // Header to indicate JSON format
neoAjaxSendEx [url] "POST" [headers] [dataToSend] "json" "handleSuccess" "handleError"
.Place this code in handleSuccess subroutine:
AlertBox "Success" "Response: [AjaxResponse]" ""
Return
.Place this code in handleError subroutine:
AlertBox "Error" "There was an issue with the request." ""
Return
neoAjaxSendEx Command:[url]: The endpoint to your Node.js server."POST": The HTTP method for the request (use "GET" if you don't need to send data).[headers]: Headers for the request (e.g., Content-Type: application/json for JSON data).[dataToSend]: The data payload as a JSON string if needed."json": Specifies the expected response type."handleSuccess": Subroutine for handling successful responses."handleError": Subroutine for handling errors.node server.js).neoAjaxLoad request in VisualNEO Web by running your project.const cors = require('cors');
app.use(cors());
This approach will enable your VisualNEO Web app to communicate with a Node.js backend, allowing for dynamic data processing, interactions with databases, or other server-side operations.
Quote from caro on November 11, 2024, 5:37 pm@luishp
Thanks , but issues not Resolved
I executed your script to start the express server and i got this
............... Cannot Get / ................ I dont know why ?instead i executed my script below . and the server started with the message
" hello from Express " as expectedimport express from "express"; const app = express(); const PORT = 3000; app.get("/", (req, res) => { res.send("Hello from Express!"); }); app.listen(PORT, () => { console.log(`Express server running at http://localhost:${PORT}/`); });then i started to execute my java script from neoweb , and no response from
the server localhost:3000 ( error empty.)
( for ex . when php server starts the app forwards to localhost )in this case there is no connection with the node,js server
My problem :: I played with so many java scripts from visual studio code with success without
even starting the node.js server . I modified scripts with visual studio without problems .
i wanted to pack my project with Visual neoweb .
I evaluated visual neo web with databases , tables etc . this was was my last chapter
( with Nodejs functions ....)
I just want to forward my code to nodejs and get results as i do with Visual studio code and from
nodjs command prompt . straightforward !
how i can resolve Neoweb communication problems with the server ??Appreciated responses from Experts who dealt with such kind of problems .
( please , look my second post in thr thread) Thanks !
Thanks , but issues not Resolved
I executed your script to start the express server and i got this
............... Cannot Get / ................ I dont know why ?
instead i executed my script below . and the server started with the message
" hello from Express " as expected
import express from "express";
const app = express();
const PORT = 3000;
app.get("/", (req, res) => {
res.send("Hello from Express!");
});
app.listen(PORT, () => {
console.log(`Express server running at http://localhost:${PORT}/`);
});
then i started to execute my java script from neoweb , and no response from
the server localhost:3000 ( error empty.)
( for ex . when php server starts the app forwards to localhost )
in this case there is no connection with the node,js server
My problem :: I played with so many java scripts from visual studio code with success without
even starting the node.js server . I modified scripts with visual studio without problems .
i wanted to pack my project with Visual neoweb .
I evaluated visual neo web with databases , tables etc . this was was my last chapter
( with Nodejs functions ....)
I just want to forward my code to nodejs and get results as i do with Visual studio code and from
nodjs command prompt . straightforward !
how i can resolve Neoweb communication problems with the server ??
Appreciated responses from Experts who dealt with such kind of problems .
( please , look my second post in thr thread) Thanks !

Quote from luishp on November 11, 2024, 9:20 pm@caro I think you don't plenty understand how the client - server programming works on web apps:
1. Running Node.js Scripts in VisualNEO Web
VisualNEO Web, primarily built for frontend JavaScript, doesn’t natively support Node.js modules (e.g.,
requirefunction). Node.js operates in a backend environment, which isn't available directly within the web-based context of VisualNEO Web.2. Options for Integrating Node.js:
- Using
neoAjaxPlugin: You can execute Node.js scripts on a backend server and then communicate with your VisualNEO Web app via AJAX. TheneoAjaxplugin can handle requests and responses in JSON, passing data between VisualNEO Web and your server.- NW.js for Desktop Apps: For Node.js functionality in a desktop app, compile your VisualNEO Web app using NW.js. This environment supports Node.js natively, allowing you to include Node.js modules (like
fs) within VisualNEO Web usingBeginJSandEndJS.Example Using NW.js:
BeginJSconst fs = require("fs");const content = "Sample content for NW.js and Node.js integration";fs.writeFileSync("example.txt", content);console.log("File written successfully in NW.js environment");EndJS
3. Limitations in Web Apps: Since frontend JavaScript (VisualNEO Web's primary runtime) doesn’t support
requirestatements or Node.js-specific modules, you’ll encounter the "ReferenceError: require is not defined" error. This restriction applies to all frontend JavaScript environments, not just VisualNEO Web.4. Additional Resources:
- For AJAX and JSON communication, review the
neoAjaxplugin documentation.- To dive into NW.js setup, consult NW.js setup guides in our support forum section to prepare your VisualNEO Web app for desktop usage.
Now lets try with a NodeJS script running a local web server:
1. Setting Up the Node.js Server
Since your Node.js server setup works and responds with "Hello from Express!", we know the server is running correctly on
http://localhost:3000. Now, let’s ensure VisualNEO Web can communicate with this server.Here’s a refined version of the server code to verify it listens and serves correctly:
import express from "express"; const app = express(); const PORT = 3000; app.use(express.json()); // Middleware for JSON parsing app.get("/", (req, res) => { res.send("Hello from Express!"); }); app.post("/data", (req, res) => { const { message } = req.body; console.log("Received from VisualNEO Web:", message); res.json({ response: "Data received successfully!" }); }); app.listen(PORT, () => { console.log(`Express server running at http://localhost:${PORT}/`); });
In this setup:
- The
/route returns "Hello from Express!" as expected.- A
/dataPOST route accepts JSON data, which VisualNEO Web will use to send data to the server.2. Setting Up Communication in VisualNEO Web Using
neoAjaxTo communicate with this Node.js server from VisualNEO Web, use the
neoAjaxplugin for AJAX requests. Ensure the server and VisualNEO Web are on the same machine (or network) andlocalhost:3000is accessible.Sample AJAX Code in VisualNEO Web
Here’s how to send data to the Node.js server from VisualNEO Web:
- Add an AJAX call to your VisualNEO Web project:
- Create a Button (or any trigger) in VisualNEO Web.
- In the Button’s Click event, add the following NeoScript code:
neoAjaxSend "http://localhost:3000/data" "POST" '{"message":"Hello from VisualNEO Web!"}' 'json' "onSuccess" "onError""onError"- Define the Callback Functions:
- After the AJAX call, define the
onSuccessandonErrorcallbacks to handle server responses.onSuccessAlertBox "Success" "Server response: [response]" ""onErroronError
AlertBox "Error" "Failed to connect to the Node.js server." ""- Testing the Communication:
- Start the Node.js server if it isn’t already running by executing
node yourserverfile.js.- In VisualNEO Web, run the app, click the button, and check if you see the success message with the server’s response.
3. Troubleshooting Common Issues
If you encount issues, here are common troubleshooting steps:
- Verify the Server is Running: Ensure the Node.js server logs show it’s running on
http://localhost:3000.- Check CORS Policy: If VisualNEO Web is hosted elsewhere or runs into cross-origin errors, use CORS middleware in Node.js:
import cors from "cors";
app.use(cors());
- Inspect Developer Console: In the browser (F12), check for network errors or CORS issues in the Console and Network tabs.
Conclusion
Using
neoAjaxwith VisualNEO Web enables seamless communication with a Node.js backend. By configuring the Express server and AJAX properly, you can achieve the same backend connectivity as with Visual Studio Code, but now within the VisualNEO Web environment.
@caro I think you don't plenty understand how the client - server programming works on web apps:
1. Running Node.js Scripts in VisualNEO Web
VisualNEO Web, primarily built for frontend JavaScript, doesn’t natively support Node.js modules (e.g., require function). Node.js operates in a backend environment, which isn't available directly within the web-based context of VisualNEO Web.
2. Options for Integrating Node.js:
neoAjax Plugin: You can execute Node.js scripts on a backend server and then communicate with your VisualNEO Web app via AJAX. The neoAjax plugin can handle requests and responses in JSON, passing data between VisualNEO Web and your server.fs) within VisualNEO Web using BeginJS and EndJS.Example Using NW.js:
BeginJSconst fs = require("fs");const content = "Sample content for NW.js and Node.js integration";fs.writeFileSync("example.txt", content);console.log("File written successfully in NW.js environment");EndJS
3. Limitations in Web Apps: Since frontend JavaScript (VisualNEO Web's primary runtime) doesn’t support require statements or Node.js-specific modules, you’ll encounter the "ReferenceError: require is not defined" error. This restriction applies to all frontend JavaScript environments, not just VisualNEO Web.
4. Additional Resources:
neoAjax plugin documentation.Since your Node.js server setup works and responds with "Hello from Express!", we know the server is running correctly on http://localhost:3000. Now, let’s ensure VisualNEO Web can communicate with this server.
Here’s a refined version of the server code to verify it listens and serves correctly:
import express from "express";
const app = express();
const PORT = 3000;
app.use(express.json()); // Middleware for JSON parsing
app.get("/", (req, res) => {
res.send("Hello from Express!");
});
app.post("/data", (req, res) => {
const { message } = req.body;
console.log("Received from VisualNEO Web:", message);
res.json({ response: "Data received successfully!" });
});
app.listen(PORT, () => {
console.log(`Express server running at http://localhost:${PORT}/`);
});
In this setup:
/ route returns "Hello from Express!" as expected./data POST route accepts JSON data, which VisualNEO Web will use to send data to the server.neoAjaxTo communicate with this Node.js server from VisualNEO Web, use the neoAjax plugin for AJAX requests. Ensure the server and VisualNEO Web are on the same machine (or network) and localhost:3000 is accessible.
Here’s how to send data to the Node.js server from VisualNEO Web:
neoAjaxSend "http://localhost:3000/data" "POST" '{"message":"Hello from VisualNEO Web!"}' 'json' "onSuccess" "onError""onError"onSuccess and onError callbacks to handle server responses.AlertBox "Success" "Server response: [response]" ""onError
AlertBox "Error" "Failed to connect to the Node.js server." ""node yourserverfile.js.If you encount issues, here are common troubleshooting steps:
http://localhost:3000.import cors from "cors";
app.use(cors());
Using neoAjax with VisualNEO Web enables seamless communication with a Node.js backend. By configuring the Express server and AJAX properly, you can achieve the same backend connectivity as with Visual Studio Code, but now within the VisualNEO Web environment.
Quote from caro on November 13, 2024, 12:27 pm
1,
Working with NW.js for Desktop i a Piece of cake . I played with a bunch of javascripts/functions without an issue .
i managed with javasript the following .
-to read a textfile and put in variable ,
- to read a specific line from a text file ( in my test lin 453 )
- replacing a specific line with a new text ( which was messy , but works fine
- and building my first plugin with these functions .2, Creating a node server is easy as well with many alternatives ,even started the server on port 8080.
your refined server.js from my original script wont start and the following
shows in the debug console . in case if it reveals something.......
....................................... debug console ................................. at <anonymous> (node:internal/modules/cjs/loader:1503:5) at <anonymous> (node:internal/modules/cjs/loader:1689:10) at <anonymous> (node:internal/modules/cjs/loader:1318:32) at <anonymous> (node:internal/modules/cjs/loader:1128:12) at traceSync (node:diagnostics_channel:315:14) at wrapModuleLoad (node:internal/modules/cjs/loader:218:24) at executeUserEntryPoint (node:internal/modules/run_main:170:5) at <anonymous> (node:internal/main/run_main_module:36:49) Process exited with code 1Setting Up the Node.js Servers not not an issue .
The problem is Setting Up Communication in VisualNEO Web !
According to my understanding only neoajax used for communication with visualneo web.
there are no working examples or tutorials regading this either on the forum or help file , as far as i know.I have tried your suggestions and show error messages ("Failed to connect to the Node.js server")
I have double checked the node server is running and if it reacts with other software.console reads
GET http://localhost:3000/data?{%22message%22:%22Hello%20from%20VisualNEO%20Web!%22} net::ERR_FAILED 200 (OK)NO CORS issues reported ! i tested to ... with Cors unblock extension to get rid of a cors error.
i think it is a good idea to Configure the Backend to allow /not allow CORS . and find solutionsIn my Understanding Node is just a way to to run JavaScript outside the browser. It can be
used to run desktop app servers or anything else that the user want to do with
JavaScript , in Our case Visualweb.In my understanding the server will listen on the port that we want so that we
have this server object pass it that port variable that we created to tell it, and takes a function.The best solution is :: if you make a working example app which shows the communication with the nodejs server and post it.
as well an example how to execute a java script with Ajax call . The Novice and New beginners appreciate this .
offcourse ! the user should be able to start the nodejs server.
If the app example works, which certainly do, the chat will be short , and the Novice will have a Nice curve of learning.
for ex how i do this with ajax call to return my variable to neoscript , if the communication goes a success . ?const fs = require("fs") const content1= "89075337635954647102216077828334038179638322940664906113645556950358984065099 test1" fs.writeFileSync("content1.txt", content1); console.log("Done writing") // passing result to neoscript $App. dat1 = content1 ;
1,
Working with NW.js for Desktop i a Piece of cake . I played with a bunch of javascripts/functions without an issue .
i managed with javasript the following .
-to read a textfile and put in variable ,
- to read a specific line from a text file ( in my test lin 453 )
- replacing a specific line with a new text ( which was messy , but works fine
- and building my first plugin with these functions .
2, Creating a node server is easy as well with many alternatives ,even started the server on port 8080.
your refined server.js from my original script wont start and the following
shows in the debug console . in case if it reveals something.......
....................................... debug console .................................
at <anonymous> (node:internal/modules/cjs/loader:1503:5)
at <anonymous> (node:internal/modules/cjs/loader:1689:10)
at <anonymous> (node:internal/modules/cjs/loader:1318:32)
at <anonymous> (node:internal/modules/cjs/loader:1128:12)
at traceSync (node:diagnostics_channel:315:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
at executeUserEntryPoint (node:internal/modules/run_main:170:5)
at <anonymous> (node:internal/main/run_main_module:36:49)
Process exited with code 1
Setting Up the Node.js Servers not not an issue .
The problem is Setting Up Communication in VisualNEO Web !
According to my understanding only neoajax used for communication with visualneo web.
there are no working examples or tutorials regading this either on the forum or help file , as far as i know.
I have tried your suggestions and show error messages ("Failed to connect to the Node.js server")
I have double checked the node server is running and if it reacts with other software.
console reads
GET http://localhost:3000/data?{%22message%22:%22Hello%20from%20VisualNEO%20Web!%22} net::ERR_FAILED 200 (OK)
NO CORS issues reported ! i tested to ... with Cors unblock extension to get rid of a cors error.
i think it is a good idea to Configure the Backend to allow /not allow CORS . and find solutions
In my Understanding Node is just a way to to run JavaScript outside the browser. It can be
used to run desktop app servers or anything else that the user want to do with
JavaScript , in Our case Visualweb.
In my understanding the server will listen on the port that we want so that we
have this server object pass it that port variable that we created to tell it, and takes a function.
The best solution is :: if you make a working example app which shows the communication with the nodejs server and post it.
as well an example how to execute a java script with Ajax call . The Novice and New beginners appreciate this .
offcourse ! the user should be able to start the nodejs server.
If the app example works, which certainly do, the chat will be short , and the Novice will have a Nice curve of learning.
for ex how i do this with ajax call to return my variable to neoscript , if the communication goes a success . ?
const fs = require("fs")
const content1= "89075337635954647102216077828334038179638322940664906113645556950358984065099 test1"
fs.writeFileSync("content1.txt", content1);
console.log("Done writing")
// passing result to neoscript
$App. dat1 = content1 ;