SpiderBasic as server-side language?

Everything else that doesn't fall into one of the other categories.
mahan
Posts: 19
Joined: Sun Nov 15, 2015 9:44 pm

Re: SpiderBasic as server-side language?

Post by mahan »

To get going with server programming together with SB I'd recommend Node.JS as a server platform:

Basic steps needed:
  1. Go to https://nodejs.org/en/
  2. Download Node.JS for your OS and Install (there are versions for every OS SB supports)
  3. Create an empty directory for your Node.JS project somewhere
  4. Go to the directory
  5. type "npm init" <press enter> and just accept all defaults (<press enter> some more)
  6. type "npm install express --save" <press enter>
  7. create a file called "main.js" with the code I provided below.
  8. create another directory called "sbclient" inside the Node.JS project directory (Node will serve static files, that is: your SB program, from here)
  9. create an empty file in this directory called "index.html"
  10. Open compiler options in SB and point your export settings "HTML filename" to the index.html file in the "sbclient" directory you just created.
  11. Make sure you check the checkbox called "Copy SpiderBasic libraries"
  12. Close the compiler options dialog with OK-button
  13. In SB menu use "compiler"->"export" (the "sbclient" library should now be populated with your project.)
  14. Go back to the Node.JS directory with terminal (OS X/Linux) or cmd.exe (Windows)
  15. Type "node main.js" <press enter>
  16. In your web browser write the address: "localhost:3000" <press enter>
  17. (If you want to stop the server (or restart it after making changes) Press CTRL+C)
If you did everything correctly you now have a (fully programmable and high performance) web server, serving your SB program.

It's very easy to extend the main.js with url-handlers so that you can use HTTPRequest from SB and get results from server side, but I'll leave that as an exercise to you. (Google some examples/tutorials from the Express JS web site)

Someone mentioned web hosting, and I'd recommend using one that explicitly supports Node.JS if you go this path. Then "Long running process" is no problem.

main.js

Code: Select all

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

app.use(express.static(__dirname + '/sbclient'));

var server = app.listen(3000, function() {
  a = server.address();
  console.log('App listening at http://%s:%s', a.address, a.port);
})
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: SpiderBasic as server-side language?

Post by Fred »

This is great info, thanks !
Post Reply