Load jQuery in node.js CLI [duplicate] - javascript

This question already has answers here:
Can I use jQuery with Node.js?
(21 answers)
Closed 6 years ago.
I'm an R developer by day and I'm trying to learn to do stuff with Javascript at night. I'm very used to the REPL type environment where I can run code in the IDE where I'm working. The code I'm writing is for a web application, but I'm still in the learning stage with Javascript so I want to do exploration, practice, etc. and I'd like to do it in a REPL environment so I can try something, fail, try something else, etc.
I have installed node.js and configured Sublime Text to "build" my Javascript files via node in the CLI. However, I'd like to try using some things from jQuery. Is there a way for me to load jQuery into the node.js execution environment so my standalone script can use the necessary features?
To be clear, I'm not talking about use node.js on a server, as a webserver, any of that. I'm just using node.js as an execution environment on my PC to execute vanilla and, hopefully, slightly french bean vanilla code.
I've read that you can't source in other Javascript files but obviously a web browser loads in code from multiple sources and co-mingles them so it seems like I should be able to do something similar when executing on my local machine.

If you just want to try jQuery in a REPL environment, you can do that from the dev tool from your browser (major browsers has it called 'console' under F12 usually), no need for nodejs here, JS engines are implemented in browsers.
But if you want to use the same core functionality and syntax of jQuery, you might want to try cheerio package https://cheerio.js.org it's a:
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.

Related

Chrome Debugger for JS file only

So. Dumb question.
I am using developer tools on chrome as essentially my IDE in the source tab. I have a JS file writing a program with no associated html/css files. Is there anyway for me to utilize the debugger for my JS file? Specifically I want to step into a function
In developer mode, select Sources tab, then navigate to your JS files in the left side. In the right panel, you can add a breakpoint to any line by pressing the line number which has a real js statement. Then you can run your application again to debug your js scripts.
The picture below is an example(Line 33 of assert.js is selected).
There are a number of different ways to debug/test your JS code, Chrome is only one of them.
QUOKKA
Quokka.js is a developer productivity tool for rapid JavaScript / TypeScript prototyping. Runtime values are updated and displayed in your IDE next to your code, as you type.
Runkit notebook
RunKit notebooks completely remove the friction of trying new ideas. With one click you’ll have a sandboxed JavaScript environment where you can instantly switch node versions, use every npm module without having to wait to install it, and even visualize your results. No more configuration, just straight to coding.
Hopa
Hopa is a zero config JavaScript/TypeScript runner right in your terminal.
JSComplete playground
This is a playground for JavaScript and React. You can use it to test simple code or prototype ideas. It requires a modern browser that understands ES2015 (ES6).
VSCode extensions Javascript REPL
Javascript REPL is a javascript playground for Visual Studio Code with live feedback(logs or errors) as you type, besides your code, in a log explorer, or in an output channel. It supports Javascript, TypeScript, CoffeeScript and it can be used for development in Node.js projects or with front-end frameworks like React, Vue, Angular, Svelte etc.

How to write iMacros scripts in javascript using scripting interface and call those from batch files

Sorry this is a relatively simple question, but there's some confusion between the firefox javascript scripting interface and the scripting interface that comes with the enterprise version of iMacros.
Here's what I'm trying to do:
Make a javascript file which utilizes the enterprise version of iMacros' scripting interface. Not the one bundled with the firefox version.
Be able to use any browser via that scripting interface. This means using iimOpen("-fx") for firefox, -ie for IE, -cr for chrome, etc, using the command reference found here
Be able to call that javascript file from a .bat file so that I can automate it with Windows Task Scheduler
I've searched around a lot, and most questions are related to the firefox-specific scripting interface and are only for javascript/one browser. The few that are using the enterprise scripting interface don't have good answers/examples. I basically just want to have the shell of what I need to get started so that I can just start writing the actual script with iimPlayCode() calls. I'm new to javascript for scripting purposes, and most things I've done are using projects such as visual studio solutions, so I'm used to imports and such. For example, what do I need to define so that the script knows how to interpret iMacros commands? Usually that would be an import, but do I need an import for a script or is that built in somehow? Do I need a main or something similar? etc
There's this example on the iMacros wiki, but it's built like an html file that you have to click to start, and I don't think that'd work well with a batch file for scheduling. As far as I know, that's the only javascript example using the enterprise scripting interface.
System information:
Windows 10
iMacros 11.1 Enterprise
Latest Firefox/Chrome/IE

Compile Error in JavaScript: "libraryVar is not defined"

I am new to JavaScript (coming from c++) and asking myself whether it is possible to compile and debug JavaScript code. I tried to use VisualStudio2012 and SublimeText2 with Node.js, but in both cases, I got a compile error when I tryed to use a library (3djs).
In SublimeText2 the error message is "ReferenceError: d3 is not defined".
I got that error trying to compile this d3js example: http://bl.ocks.org/mbostock/3828981
Strangely the example worked perfectly when I opened it in some browsers..
Can anyone tell me what I am doing wrong or whether it is even possible to compile or debug JavaScript code?
(Sorry, this seems to be a very beginner question but I did not find the answer searching for some hours...)
Best regards!
node.js also doesn't compile the JavaScript (not in the C++ sense; JavaScript interpreters often Just-in-Time compilation). The main difference between node.js and a browser is that node.js doesn't try to hide errors from you.
So the first question is whether you correctly included the library in your project. For this, we need to see the source code that you use to load / import it.
If you're sure that the library has loaded correctly, then you might be triggering a bug in the JavaScript interpreter. Try to install the latest version or the lastest stable version or the version before that.
[EDIT] In HTML, you use a <script> element to include scripts in the context of the page. When using node.js, then you have to use require():
var d3 = require('./d3.js')
That said, D3.js is a client framework. It expects the standard browser environment like a DOM. It will not work inside of node.js. node.js expects modules (= stuff that you can import using require) to have a certain format.
So the simple answer is: You can't "compile" and debug JavaScript code in your IDE. You always need to create a HTML page and open that in a browser. All modern browsers have consoles, plus tools to debug and examine JavaScript, CSS, HTML and the DOM.

Is it possible to run native python code in chrome? [duplicate]

This question already has answers here:
How can I integrate Python and JavaScript?
(13 answers)
Closed 13 days ago.
I was wondering if it is possible to run native python code in chrome instead of javascript.
I have seen projects like pyjs or brython, but what they do is compile python to javascript. While those are great projects a problem with this approach is always that you cannot easily debug the original python code.
Amongst other things I stumbled upon this thread, describing how to develop custom code for chromes-sandbox. But this would probably lead to implementing a python interpreter in the sandbox, which would be an overkill.
Any help is appreciated! (I don't want to start any python vs. javascript discussions, but only find out if this would be possible and if so, how to do it)
Kind Regards,
Marco
Python is a programming language, you can't run native code of a programming language. You can however, run programs written in python in the browser.
So can I run python code in the browser or not?
Update June 2013: The Brython project is now available letting you run Python 3 code in your browser. You can check it out at http://www.brython.info/ .
You can use run LLVM in JavaScript using ECMAScripten. This means you can compile c-python from C to JavaScript and just run JS in the browser. The link to the ECMAScripten wiki provides more details on how to do that.
(Here is a live demo of a python REPL running in the browser)
There also exist python 2 implementations that work in the browser.
But should I?
Probably not, JavaScript and python are similar in many things, both are dynamic, both are compact and both are clever. If you know python you can learn JavaScript very quickly.
If you like python's syntax, you might want to consider CoffeeScript which has similar syntax to Python (and somewhat to Ruby) and compiles to JavaScript transparently.
Solutions that run python in the browser will also tend to be much slower, at least until more browsers will support asm.js (currently only firefox nightly).
I believe you can create a compiler in Javascript, to run simple python code. There are probably some available programs as well that will allow this to be carried out. Although, it is not possible to run python directly through a web browser.
Now , it's possible . you can run python in browser

What is the most normal way to deliver a ClojureScript desktop application

I have a desktop application written in Clojure that suffers greatly from JVM startup time and is a really good fit for ClojureScript. It is delivered as a jar file for the JVM, what is the equivalent for ClojureScript/JavaScript?
The deployment rules for regular javascript apply. There's nothing wrong with just sending the user the optimized .js file emitted from clojurescript's compiler. Usually this means double clicking the script or running from command line as if it were python or ruby.
Can you do Desktop Development using JavaScript?
For windows machines, you have Windows Script House http://msdn.microsoft.com/en-us/library/9bbdkx3k(VS.85).aspx
If you run a *nix you can use Node.js http://nodejs.org/
Note: You may need to lookup tips for getting google's closure library to work with node.js via https://github.com/hsch/node-goog if you will depend on it.
Or something like this? https://github.com/maccman/macgap

Categories