interact with a console program using javascript - javascript

I'm currently making a chess web-based app. Now that I want to add in the stockfish chess engine which I will have to interact with in the command line. I've searched the internet and there's the child_process exe related to Node.js. I know how to use it, but only when it is compiled with Node (for example "node file.js" in the command line) but then i don't know how to call that from my main javascript file which contains the chessboard and stuff.
Is there a way to do it (if that's even possible) or you may suggest me another way to do it please :D ?

As you using stockfish - It's not necessary to be CLI version.
Here is a pure JavaScript implementation:
https://www.npmjs.com/package/stockfish

Related

Compiling Node.js into an executeable without putting the entirety of Node.js in there

So, I'm trying to pack a simple hello world script into an executeable, yet when using pkg or nexe, it looks like the entirety of Node.js get's packed in there, as they are way bigger than they need to be (around 30 MB). I did stumble upon EncloseJS, however, it was last updated in 2017 and no longer works (and the owner themself advices you to switch to pkg).
So, are there any other things out there that can compile it better than that?
Thanks in advance!
Also: This is the stunningly complex script that needs to run
console.log("StackOverflow is amazing!");
setTimeout(() => {
process.exit(0);
}, 2000);
And my locally installed versions:
NPM
Node
6.14.12
14.16.1
No, pkg and nexe works like that - they melting your code and NodeJS in one executable. Because, basically, you need NodeJS to run nodejs scripts - there is some specific methods like fs, for example, witch not exist in regular js.
Anyway, on this moment there is some projects to view:
NectarJS - project with actual dev status, basically compiles JS to C. But their main objectives is pretty interesting.
There is small JS engine called QuickJS witch compiles JS to C.
Another option is ts2c witch translate JS to C, but it does not
support much features.
But keep in mind, that non of them works as good as pkg, witch fully support latest JS features and all NodeJS methods.

Make a React WebPage for local use

I started coding recently in JavaScript and started to make a little WebPage that's am gonna present it to a Client.The thing is that you need a server to run the webPage, I can't make the client open one each time ... (I could have gone for another language to make it Offline and easier, but I wanted to try JS for the GUI and performance).
So I thought about making some sort of a .bat file to open the server,Open the html file,when html is closed, the servers shuts down.(I know NOTHING about .bat files...)
after a little research I found that I can do it using Python and it's easy,but even then , I have to install Py. on the clients computer and I want to avoid that.
And more over, I found that my App doesn't work on Python's server or for the LiveServer extention from VS Code. (Yes I am new to React, I used npm to download a WebPackage, Used 'npm start' for the server and it works fine, it must be a probleme in the html when when importing js or when using ReactDOM.render).
This might be a little complicated but please if anyone have a suggestion then I will be grateful.
If you are using create-react-app, You can run yarn build and it will create the production build in your build folder. just run index.html in a browser and it will run the website without any server.
I think you should use Electron it helps you to build cross-platform desktop apps with JavaScript, HTML, and CSS.
I've used phpDesktop for building a desktop application using PHP, but this is better in every aspect.
ElectronJS Homepage
This is a great Electron Crash Course

How to compile Javascript console application locally?

I am a beginner in Javascript, I decided to practice Javascript by problem solving using it, I found an online judge that accepts Javascript V8 4.8.0 code.
So, I searched online to get that version of Javascript V8 on my machine, but I couldn't find any easy way, All the pages were explaining how to build it, and it seems to be a process that I don't need to go through.
Is there an easy way to compile and run command line apps written in Javascript on my machine?
Note: I don't want to use node.js because I tried using it's I/O and
as a beginner I think it is complex in some way.
Update: I found that package manager pbox.me which provides a version of V8 JavaScript Engine and I managed to install it.
Yet another problem appeared: whenever I try to run a js file writing d8 myfile.js in command line nothing happens as if it is an empty program, knowing that I tryied to d8.exe file and it is working, and I made sure the PATH is inserted in the environment variables.
What am I doing wrong?
The easiest way to get started with JavaScript is probably to use it in a browser. You can type simple things directly into the browser's JavaScript console (check the menu); or you can embed your code in a simple HTML document.
If you want, you can even pretty easily implement the readline()/print() functions, so you can pretend to be doing stdin/stdout based I/O: just read from an array of strings, and send output to console.log (or create DOM nodes if you want to be fancy and/or learn how to generate dynamic website content by hand).
Side note: V8 4.8 is severely outdated, don't use it to execute code you haven't written yourself.

Azure documentdb how to develop server side?

as a total JavaScript beginner, how do I actually develop for it?
I mean, I've seen https://azure.microsoft.com/en-us/documentation/articles/documentdb-programming/ but there was no mentioning of a development environment.
Is there something like a visual studio project template for server-side javascript?
I use node.js so your mileage may vary if you are developing from .NET, but here's what I do:
First of all, I created an npm package documentdb-utils. It is a wrapper for the DocumentDB node.js package that makes it easier to do a bunch of things.
Then, I created npm package documentdb-mock to write tests for my stored procedures. The source code for documentdb-mock includes 4 example stored procedures along with a test suite for each using nodeunit. You can start with these as they exercise most of the server-side API.
After I have them passing my local unit tests, I write integration tests that exercise my system end-to-end including creating any necessary data for each test run. The only problems that I've found here with sprocs that I didn't see in my mocked testing had to do with reaching certain limits... although, documentdb-mock has been upgraded to simulate many of these now also.
I haven't open sourced this yet, but I have also written a parser/rewriter that will embed any require(d) packages into my sprocs before sending them to DocumentDB. This allows me to write and test in a nicely factored way on node.js even using downloaded packages from within my sprocs, but when they get pushed to DocumentDB any dependencies are automatically embedded inside of the function. I'll open source that at some point (probably adding it to documentdb-utils) but I can share it with you now if you desire.
Here are a few tools that I found helpful for development (especially server-side [by which we mean database-side] scripting):
DocumentDB Studio - https://github.com/mingaliu/DocumentDBStudio/releases
Sample Code - https://github.com/Azure/azure-documentdb-js-server/tree/master/samples/stored-procedures
Here is another nice open source tool for exploring data in documentdb:
documentdb.a7pl.us

Starting a process via Javascript [Using Rhino JS]

I'm working with a tool that only allows for Javascript as the scriptting language. With the script, I need to launch a process. How would I go about this?
The javascript code is running on the client that will launch the process. The javascript interpeter is RhinoJS.
So my question remains:
1. Is there a way that I can call a specific Java class from Rhino [ProcessBuilder]?
or
2. Is there a way to launch an executable from Javascript? [I've tried the UniversalXPConnect route, but it turns out that the version of Rhino I'm using doesn't really worry about permissions]
That was quick [I found the answer right after I asked]:
var pb = new java.lang.ProcessBuilder("notepad.exe", "c:\test");
pb.start();
Basically RhinoJS has a quirk to allow it to directly access Java functionality. So basically once should just launch the process from there.

Categories

Resources