Running JavaScript Code from JSDB Shell

The JSDB (JavaScript Database) package can be downloaded from http://www.jsdb.org/download.html (the one without ODBC should suffice for the purpose here).

Extract the downloaded zip file. You will get the JSDB executable file, which is the JavaScript interpreter.

Navigate to the directory where the extracted jsdb executable file is located. Open the terminal and type the command

				jsdb
			

It will show the prompt js>. Test print a line of JavaScript code

				js> writeln("Hello, World!")
			

Many such JavaScript code snippets can be run from the JSDB shell for testing and experimenting.

Running JavaScript File

Create a JavaScript file called hello.js. For our example, we will insert a one-line code to print Hello, World!

					writeln("Hello, World!")
				

and save it in the same location as the jsdb interpreter. Next, run hello.js by typing the command

					js> run("hello.js")
				

Executing Explicitly

The hello.js script file can also be executed explicitly by specifying the Node.js interpreter. First exit from the js> prompt. Assuming that you are in the same location as the jsdb interpreter and hello.js, run the below command from the terminal

					jsdb hello.js
				

Notes

  • If during execution of the script it gives error like "jsdb: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory" in some Debian-based distributions (such as Ubuntu), install the lib32stdc++6 package.
  • Browser Window objects like document, location, navigator, screen, history will not work in JSDB.