I am trying to run some javascript code on a browser or on a server.
That includes the ES 6 yarn package and node.js. When I run the command from the terminal it launches a local server on a browser and everything works fine.
But if I try to run the HTML file from the folder or uploading the files onto a server, it doesn't work and it doesn't recognize any of the code I wrote.
How can I fix this?
It sounds like you something like Babel in your terminal step somewhere that transpiles your javascript code and launches a browser to serve the code in memory.
In order to have it work in an html file or on your server, you'll have to transpile your javascript code to use in HTML files.
Browsers do not currently understand all ES6 syntax, almost any ES6 javascript code needs to be transpiled for the browser as of today.
Related
Would like to try this Rhino Debugger however having problems
I downloaded latest from here according to doc it says just simply run:
java org.mozilla.javascript.tools.debugger.Main [options] [filename.js] [script-arguments]
however..it's source code, so I probably need to build it first...(unless there are precompiled download out there?). Assuming I need to build it to get the jar file for debugger, I assume just build the build.gradle file at the root dir. Or run gradle tasks build ? When I do that I get error:
Execution failed for task ':checkstyleMain'.Unable to create a Checker: configLocation {C:\rhino\rhino-1.7.8\checkstyle.xml}, classpath {C:\rhino\rhino-1.7.8\buil
dGradle\classes\java\main;C:\rhino\rhino-1.7.8\buildGradle\resources\main}.
So..I'm a bit lost. Been ten years since I've worked with Java, but hopefully I'm missing something simple.
Any experienced Rhino JavaScript devs out there that can point me in the right direction? Should I just stick with using Eclipse? (Had that working, but I'm still curious about this debugger)
Download the latest rhino from the link you provided, at this time it is "rhino-1.7.8.zip". Unzip that and change directory to "rhino1.7.8/lib"; you need the "rhino-1.7.8.jar" in your CLASSPATH. Assuming you are in "rhino1.7.8/lib" that should be in your current folder, and you can then do
java -cp rhino-1.7.8.jar org.mozilla.javascript.tools.debugger.Main
Which should render like
I am willing to make a portable app using HTML CSS JS and similar languages that doesn't need any installation and can be accessed via a browser.
The app should be able to access the file system and create, write and delete files.
The required files will be on the local machine.
I have tried
Applets but the performance is too inconsistent and depends on browsers.
I have also tried using electron but the end result needs installation (correct me if I am wrong)
I am open to all suggestions
Electron's apps can be portable. Copy the electron build resulted folder into a pendrive and execute the main .exe file from there. Everything should work
I want to write a JavaScript example and run it to see how something works.
The sample code might require a browser but not always. I'm open to two solutions, one that works with NodeJS, and one that is used for browser based code. In browser, I'm using React with class and other ES6 syntax including import/export which is not (yet) supported directly by node or node --harmony.
In Python, Java/Groovy, C/C++, C#, others, I could just run a command to compile the file and then run the executable (or just interpret the code), so I'm looking for something similar for JavaScript.
Conceptually, I would like to say:
dotranspile --out bundle.js main.js
node bundle.js (or firefox index.html, which loads bundle.js)
The key is that I don't want to have to create a webpack configuration file in every directory. I thought I found a command like this when searching one day, but can't find it now.
How do other people run javascript sample programs when babel/transpiling is required? I would also like to be able to save them for future reference (in some cases).
Currently, each time I want to write a test I create a directory with a webpack.config file, package.json, and use npm install, and npm run to run the code or start a NodeJS express server to serve index.html.
This seems to be a lot of overhead for a quick test, and it results in dozens of node_module directories with tons of files in them.
Maybe is not answer that you want, but you can always use jsfiddle with babel + jsx. I think that jsfiddle is very good tool for quick run simple app in babel/jsx or other libs, transpilers etc.
I have to run a JavaScript file as an executable to show a dialog with standard buttons from command prompt.
I am new to command line programming with java script.
Standard Javascript is not something that natively runs in a command line environment. It is designed for use in browsers. However, Node.JS is a framework built to give you this exact feature of running Javascript as a standalone.
It can be downloaded from http://nodejs.org and installed on most platforms.
Once you have it you can invoke your javascript file by running
$ node <your file name here>.js
You cannot run javascript from the command-line. Usually javascript is executed in a browser.
You can, however, use javascript from server-site (or command-line) using Nodejs.
Have a look here on how to achieve this: NodeJs
Or you can use the REPL (Read-Eval-Print-Loop): Repl
I really like code-coverage reports for my code in node.js.
I've already created a node.js module that can inject instrumented code (and mock our require statements) called requiremock
I'm using that in my other module nodecoverage together with the binary version of jsCoverage (windows) to generate code coverage reports, injecting instrumented versions of code with requiremock.
The problems with using jsCoverage are
It needs compilation for the platform, because it's written in C(++), I would like to implement it in JavaScript so it can be used on any platform without compilation.
It writes the instrumented versions of code as files on disk. With requiremock I can generate the instrumented JavaScript files in memory and run those when the original file is required.
jsCoverage does not report code coverage correctly when using function hoisting, and I use that a lot in node.js
So my question is:
What JavaScript parser written in JavaScript should I choose to reimplement jsCoverage as a node.js module?
I have to be able to know the linenumber of the code in the original file, and also know what whitespacing was like.
Try esprima. It's awesome. Also node-cover potentially already does have what you need