I have simple "to-do" application written in JavaScript and HTML. I don't even have CSS file, just have bit of in-line style in index.html file where I have linked my JavaScript file. No database or any other stuff needed. Simple app using vanilla JavaScript and HTML.
I have AWS free tier account and tried zipping .js and .html files and deploying to AWS Elastic Beanstalk but it's converting into node.js and keep looking for JSON file and deployment is unsuccessful.
Is this called JavaScript app or Node.js app in real world?
How do I deploy it in AWS?
As other have answered (without telling you how to do it) the solution is static web file hosting. You do not need to deploy your app to Elastic Beanstalk as your JavaScript are not executed on the server. They just need to be served to a client where they will execute in the client’s browser.
Amazon S3 is the most cost effective way to serve static HTML website.
The easiest way to setup S3 and deploy your application is to use amplify command line.
See the detailed procedure at https://aws-amplify.github.io/docs/cli/hosting
To learn more about Amazon S3 web hosting, please read this https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html
You are a bit confused on the two "terms" -> Javascript and NodeJS.
Javascript: is a high-level interpreted programming language;
NodeJS: is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser.
So, in your case, since you are not using any "backend", as suggested by other users you should use a simple web hosting.
Node.js is a Runtime Environment to run Javascript Code on the server i.e. on any machine with an operating system. So all Node.js apps will be Javascript apps but not all Javascript apps will be Nodejs apps.
In your case since you have an HTML file and your javascript file might be manipulating the DOM it would be classified as a Javascript app for the browser.
However if you have a javascript file which is not manipulating the DOM, you can run that on a Node.js environment.
I hope i have answered your first question, although i cant answer your second question at this moment.
JavaScript is a language.node.js is not a language or a special dialect of JavaScript - it's just a thingamabob that runs normal JavaScript.All browsers have JavaScript engines that run the JavaScript of web pages. Node.js is simply the V8 engine bundled with some libraries to do I/O and networking. so that you can use JavaScript outside of the browser, to create shell scripts, backend services or run on hardware.
Related
In a server environment, I expect to write URL paths to query for data. In Electron, because I can use NodeJS in any part of the application with normal JavaScript, there seems to be no 'separation' between the two.
Where should most of the code be, especially if when using NodeJS? In the main.js file, or in the application's JavaScript file? Additionally, if a result from the NodeJS code is being written to the HTML dom, should it be written directly from the same code or stored and then written in normal JavaScript?
What is normal or good practice in Electron?
If you are new with electron and don't know where to start, I recommend to you to download this example and take a look to the reedme.txt and the code inside, it will lead you to the path to begin your app.
Take a look
I have a project to write to a postgress database from an html, in my project I included packages jquery, html, and css. I read that to access a postgress database it’s needed to have a server side package like nodejs, and I want to include this package in my project. I would appreciate if I can get sample projects or resources to do it.
NodeJS isn't a Javascript package that you can run on a browser.
Let me explain.
NodeJS started out as a project to run Javascript code outside of the browser and on top of your Operating System. This gives it access to OS specific functionality like writing to files, writing to Databases, spawning processes, starting an HTTP server etc. Much like any other general purposes programming language like Python, Ruby, Java, PHP etc.
So NodeJS is two things - the Javascript Interpreter(same as the browsers, V8 to be specific) and Libraries (like fs, vm, zip, etc).
While most of these libraries are inter-operable with the Browser's version of the Javascript interpreter via something like Browserify (Used to run node.js modules on the browser), some of them like the libraries used to write to a database are not and cannot be used on the browser.
To use the postgress database JS library, you'd have to learn node.js and expressjs. But what would be practical is to find a library specific to the framework you are using, whether it is PHP, Ruby on Rails, Django/Python etc.
I am developing a native android app using HTML/CSS/JavaScript. During the App flow, I need to permanently delete certain HTML files (stored locally). Can this be done?
I am a high school teacher trying to develop an educational app. I have basic knowledge of HTML/CSS and near zero knowledge of JavaScript!
modern broswer support javascript file operation but this file system is only in broswer and isolated from local files, refer https://developer.mozilla.org/en/docs/Web/API/File
if u do need delete file on android system, then u need your app provide a bridge to and call from js, run in app, in java code, delete the file
the code might look like
JsBradge.delete(file)
Javascript disigned as a web document script language, so it has many security essentials, such as absolute isolation in browser, which means no write acces to file system.
So, you have two options - first is create your own bridge to java, for example call prompt('your_file_name'), catch it in java and delete your_file_name.
Second - use any of mobile app framework, for example - Cordova.
Sorry, but no easy ways =(
We are building a web service for data analysis and would like to access netcdf files from the local machine where the browser is running. Javascript offers a file browser, but (for security reasons as I learned) it will automatically upload a file after selection, instead of allowing (read-only) access to it. This presents a show-stopper, because the netcdf files can be HUGE. Note, that the netcdf format and API explicitly allow slicing and extraction of individual variables, which is one reason why the format is so popular.
Now, some research into this issue revealed that the server-client architecture normally doesn't allow access to the local file structure to prevent spying. On the other hand, in HTML5 there is a file API which supports exactly the kind of operations we need -- except that you can access portions of a file by specifying byte ranges, but there is no netcdf API available; hence one would be left again with copying the entire file before being able to slice it on the server.
Of course, the other option are web services such as OpenDAP which are meant to do exactly what we want, i.e. access parts of a netcdf file over the internet. However, this of course requires that every user would have to install the OpenDAP server before they could access their local files from within the web service. (Or, at a minimum they would have to install a web server so that one could access the file via http://localhost/...).
So: does anyone know of a solution to read specific portions of a local netcdf file from a web application? Specifically, are there javascript tools available for this?
Currently you can use netcdfjs, that it's a javascript library that allows to read NetCDF v3 files. Because it's a NodeJS package you can run it server side, and for regular size files you can read it online, here you have an example.
There are no Javascript tools to read NetCDF, but there are Java libraries: http://www.unidata.ucar.edu/downloads/netcdf/index.jsp.
You could deploy a Java Applet to read the NetCDF file locally. From there you could have the Applet try to process the file, or communicate with a backend service, or even try to call on the Applet from Javascript: http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html.
There are no specific Javascript libs for reading NetCDF, as far as I know. But let me drop some thoughts:
As you say, you can install a local webserver, and use a server-side language to execute a program that reads the file in your disk. You could use a command-line software called ncdump-json. I intentionally wrote this software for that purpose.
You say that you don't want to install software like OpenDAP or webservers, but maybe a desktop app, a standalone .exe would be OK for you. Using node.js plus chromium (this is called nw.js) you have a program that is at the same time a nodejs server, and a chromium browser. This way you can write a web application that reads the data (e.g. using the embedded nodejs server and spawning ncdump-json...).
And now the simplest scenario, a 100% client-side solution... I think this can only be achieved using Javascript... or anything that can "compile to" Javascript. We need to have the netCDF libraries in Javascript, is that possible? I guess so. Emscripten is a LLVM-to-Javascript compiler, and netCDF is C so it has to be possible to compile it with clang/LLVM, therefore it has to be possible to use Emscripten to have a netCDF JS library version with almost no effort, without having to write from scratch (and also maintain) a JS port. If I'm not wrong, to random access the files there's the method slice in the html5 file api, so that should not be a problem.
Hope I helped.
Given a need to write command line utilities to do common tasks like uploading files to a remote FTP site, downloading data from a remote MySQL database etc.
Is it practical to use JavaScript for this sort of thing? I know there are JavaScript interpreters that can be run from the command line, but are there libraries for things like FTP and database access the way there are for e.g. Java? If so, what's the best place to look for them? (Google searches with JavaScript in the keywords always seem to return many pages of browser specific things.)
And is there a way to package a JavaScript program up as a standalone executable on Windows?
Update: I've decided Python is a better tool for this kind of job, but the answers to the original question are still good ones.
Standalone executable?
By the way you ask the question, I'm not sure if you are aware, but the Windows Script Host - included in Windows - allows you to run .js files from the command-line. Your javascript will not be an executable, it will remain a script, a text file. The script runs within cscript.exe, which is provided by WSH. There's no compilation required. Maybe you knew all that.
I use Javascript this way for various utilities on Windows.
I think your instinct is right on the availability of libraries. You are sort of on your own to find all those things. Although, once you find them, it's not hard to package Javascript libraries as COM components and allow re-use from anywhere. See here for an example of packaging the Google Diff/Patch/Match Javascript library in COM.
Addendum: Once a bit of code is available within COM, it can be consumed by any Javascript running on the machine. Some examples of COM objects available to Javascript scripts running in WSH:
MSXML2.XMLHTTP object - used in AJAX, but can be used for any HTTP communication. There also an object for the XSLT engine so you can do transforms from script.
Excel.Application - allows you to open up Excel spreadsheets and automate them from Javascript.
Communicator.UIAutomation - automate MS Communicator (send IM's via script)
COM objects for Google Earth.
SlowAES - an all-Javascript implementation of AES encryption.
You can use Rhino to compile Javascript into Java byte code, and get access to all Java libraries.
Or you could use JScript.net, and get access to the .net libraries. .net includes a jsc.exe that produces exe-files.
Both of these requires the respective framework to be installed to be able to run.
Node.js is by far the best environment for running non-browser JS. I've used Rhino and SpiderMonkey, and there's a pretty huge difference in everything from the basics like how errors are handled to the size of the community using the tool. Node is pitched for "server-side" JS - building server apps in JS. It's great for this. But it works equally well for building command line tools.
The NPM package manager (bundled with Node) provides a nice global directory for finding and installing packages. It works much better than other language equivalents like PECL / Pear / CPAN / etc. Several high quality tools like JSHint, The Jade templating language, and the CoffeeScript compiler are all already available through NPM/Node:
npm install -g jshint, coffee-script, jade
jshint my_code.js
jade < my.jade > my.html
For args parsing, there are packages like commander.js. I currently use a heavily extended version of Commander in my underscore-cli command-line tool.
For messing with JSON or for doing command-line JS work (similar to "perl -pe"), check out underscore-cli - It's a really powerful tool for processing JSON data, processing underscore templates, and running JS expressions from the command-line. I use it for 1001 different things that would otherwise be really annoying to accomplish.
Rhino is bundled with JDK 1.6, jrunscript.exe in the bin directory will allow you to run any Javascript you want. Since it runs under Java you get access to any Java libraries that you may have.
We use it from the command line extensively. It's very good at that.
One way is to write these utilities as AIR applications - They can be written in JavaScript and need not have a UI. They have access to the command line, and there are existing ActionScript 3 libraries that can handle FTP etc. These ActionScript APIs can be called from JS, in AIR applications. AIR applications also have access to a sqlite database.
jslibs is a good standalone JavaScript runtime that support many 3rd party open source libraries like zlib, SQLite, NSPR, libiconv, libTomCrypt, OpenGL, ...