I know there are node.js libraries for Redis; what I'd like to do is run a Redis server (either on localhost or on a server host somewhere) and call it directly via HTTP (i.e. AJAX or HTTP GET as needed) from JavaScript running inside a browser (i.e. a Greasemonkey or Chrome Extension script, or maybe a bookmarklet or SCRIPT tag). Does Redis have a native REST or HTTP API?
You can't connect directly to Redis from JavaScript running in a browser because Redis does not speak HTTP. What you can do is put webdis in front of Redis, it makes it possible work with a Redis instance over a HTTP interface.
Maybe this could be used to make a javascript client for redis? In the examples shown, commands are sent directly to the redis server, which executes them. However, practically speaking, you can use openresty+nginx in front of redis to essentially directly talk to redis over http, and get the performance benefit of nginx's multithreaded server which will share a limited set of connections to redis itself.
webdismay is a JS library I have recently released (License: MIT) to connect to a webdis+redis backend from the browser. It takes an ES6 Promises approach to communicating with the redis+webdis back end, providing functions for generic and keyless redis commands and organized classes for commands that operate on Keys/Strings, Lists, Hash and Sets. All functions/methods return ES6 Promises.
Assuming you have webdis set up with redis, in the default configuration to accept post requests to "/", then with webdismay a simple example of sending data to the server and getting it back later would look like this on the browser (in ES6):
This is not exactly beginner-friendly, yet, but could allow someone to use webdis+redis from the browser without constantly translating mentally between javascript idioms and redis and writing their own ajax.
If I have in main.js's file, global variable a = 5; and I'm sending this variable with AJAX to PHP, is it possible to change this variable from the console or somehow from the outside and have AJAX send wrong parameter?
I scrape all website links from the google search page and store them on allLinks variable. It works I check it on the console. But my writeInFile function does not work in the browser. But it works when I run it on the node js terminal. I want to make a program to scrape my data and store it on the txt file. How can I do this?
The console object provides access to the debugging console (e.g., the Web console in Firefox). The specifics of how it works vary from browser to browser or server runtimes (Node.js, for example), but there is a de facto set of features that are typically provided.
The console object can be accessed from any global object. Window on browsing scopes and WorkerGlobalScope as specific variants in workers via the property console. It's exposed as Window.console, and can be referenced as console. For example:
Note: Certain online IDEs and editors may implement the console API differently than the browsers. As a result, certain functionality of the console API, such as the timer methods, may not be outputted in the console of online IDEs or editors. Always open your browser's DevTools console to see the logs as shown in this documentation.
The console's most frequently used feature is logging text and other data. There are several categories of output you can generate using the console.log(), console.info(), console.warn(), console.error(), or console.debug() methods. Each of these results in output styled differently in the log, and you can use the filtering controls provided by your browser to view only the kinds of output that interest you.
I have Fujitsu fi-6130 TWAIN / ISIS scanners that I'd like to trigger from a button in a jQuery Rails web page. Not only would I like to have the page tell the scanner to "go", I'd also like to upload the resulting file via Paperclip once the (single) page is scanned - ideally without requiring the user to navigate a file explorer widget to find the file manually.
This question was asked almost a year ago, but mainly received suggestions requiring the use of commercial IE .NET products that cost several hundred dollars - Interfacing with the end-user's scanner from a webapp (web/scanner integration)
If you control the machines the web app will be running on, I'd recommend using a simple desktop client to perform the scan and allowing connections to it from within the webpage by opening up a local port
As @Basic mentioned, JTwain can be used to create such a solution. In fact, the developer of JTwain has created ScannerJS that allows one to scan directly from browsers like IE, Chrome and Firefox using JavaScript. In order to use it in your web pages, you need:
You're going to have to do this on the server, since that's where the original 404 response comes from. The server definitely receives the bad URL, so all that has to happen is that you make your server preserve those somewhere.
JavaScript in browsers can only GET Keyboard Maestro variables. They cannot be set. If your Keyboard Maestro Variable contains spaces, they must be replaced with underscores in the JavaScript, for example:
I've installed browserify and browserify-fs to use Node's fs module in the browser, and used the example from the browserify-fs README to create a directory, write a file to it, and then read that file:
This "works" in the sense that it logs "Hello world!" in the console. But as far as I can tell, it does not create a directory or save a file locally. I have some vague sense that it is saving these things temporarily in the browser, and that they are deleted when I navigate away. But I want to actually create a directory and save a file in it locally. Can I do that with JavaScript alone? Is there a good tutorial on how to "close the loop" between browser-based JavaScript and Node?
There are several ways to supply your credentials to the SDK from browser scripts. Some of these are more secure and others afford greater convenience while developing a script. Here are the ways you can supply your credentials in order of recommendation:
Unfortunately this header is not available for reading inside JavaScript; all you get is navigator.language, which tells you what localised version of the web browser was installed. This is not necessarily the same thing as the user's preferred language(s). On IE you instead get systemLanguage (OS installed language), browserLanguage (same as language) and userLanguage (user configured OS region), which are all similarly unhelpful.
If I had to choose between those properties, I'd sniff for userLanguage first, falling back to language and only after that (if those didn't match any available language) looking at browserLanguage and finally systemLanguage.
Roll these into a javascript function and you should be able to guess the right language, in most circumstances. Be sure to degrade gracefully, so have a div containing your language choice links, so that if there is no javascript or the method doesn't work, the user can still decide. If it does work, just hide the div.
We first check the navigator.languages array for its first element.Then we get either navigator.userLanguage or navigator.language.If this fails we get navigator.browserLanguage.Finally, we set it to 'en' if everything else failed.
A user can configure preferred languages in the browser, and these will be used for navigator.language(s), and used when requesting resources from a server, to request content according to a list of language priorities.
However, the browser locale will decide how to render number, date, time and currency. This setting is likely the highest ranking language, but there is no guarantee. On Mac and Linux, the locale is decided by the system regardless of the user language preferences. On Windows is can be elected among the languages in the preferred list on Chrome.
You can also try to get the language from the document should might be your first port of call, then falling back to other means as often people will want their JS language to match the document language.
That's fine, in my app, I just set the newly created image instantly to the image source, without reloading it from the server, and next to this, the new image is uploaded to the server. This is to ensure a very responsive feeling. The problem is that when to user refreshes the page, he sees the cached old version of the thumbnail.
I know I could use some image.jpg?sometimestamp to be sure the browser has to download a new version of the thumbnail, but as I said, the app needs to be very responsive, even on small &slow internet connections. (Thats why the app in itself is stored on the user's computer and not downloaded live. Only uploads, downloads and jsons are transitting)
df19127ead