I started learning JavaScript a while ago. It's a fairly easy programming language considering that I learned Java in university, that I know php pretty well and that I already played around with python and ruby. The problem is that to properly learn a programming language I usually create a project. In javascript, I just don't know what kind of project I could create - that is, a project that is not web-based or related to the web browser. Can I create javascript shell scripts? Where is javascript commonly used beside the web browsers?
So, can someone actually give me some ideas please?
Can I create javascript shell scripts?
You bet!
On Windows, you can do this by using cscript.exe (you can even set up a file extension -- I use jx -- that automatically runs when you just double-click the filename or use it as a command in a shell: Just associate that file extension with the command "c:\WINDOWS\system32\cscript.exe" /e:JavaScript /nologo "%1" %*). This is (and I've measured carefully) about 80 milion times better than fighting with Windows' batch language. About. (And if you don't want to use JScript — Microsoft's variant of JavaScript — you even have options, see below.)
On *nix, a shell script can be set to run in any installed interpreter (that's what the #!... line at the top is telling the command interpreter). I expect you'll find a few if you search around.
On the Mac, you probably have JavaScriptCore installed in /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc
And on all of the above, if you like, you can install Rhino and Java and get platform independence and access to a huge range of library functionality. Rhino has a built-in shell, or you can tell it to execute a specific JavaScript file. It interoperates with Java, so if you do this, you have easy access to all essentially of the functionality available to Java.
Where is javascript commonly used beside the web browsers?
I use it for shell scripting on Windows. I also use it as a server-side language, for instance in the server-side part of a web application. It's also used in other environments where a lightweight, powerful scripting language is useful, such as in the MongoDB shell environment (you can use it to query MongoDB data) and stored procedures.
All of that said, writing a browser-based project is a rich, interactive way to learn the language.
windows Sidebar Gadgets, Apple's Widgets, and Google Desktop Gadgets are all created using HTML/ JS/ CSS.
I learnt Javascript by creating a few small Windows Sidebar Gadgets.
Getting Started
Sidebar Reference
You could use javascript to make HTA (HTML Applications) that can be run outside of the the web browser sandbox. MSDN intro to HTA ApplicationsJavascript Tutorial on HTML Applications
You could write a non-blocking TCP server.
Node.js supports that.
Common uses of javascript outside of browsers are WSH scripts and HTA applications on Windows and Dashboard widgets on Mac.
Related
Ive been learning html, css, js, php, mysql, (touched on node js but ran away from it - too much too soon) for a few months now and would like to make a simple categorized code snippet app as a learning project and to aid my crap memory!
I couldnt find a relevant answer so, hopefully its not a dumb question:
I want to primarily stick with js to get a good coding knowledge base so will make the snippet app using js, and .txt files as the storage. Using VS Code, what would be the best practice/method?
I know I could just make it browser based, but would rather have a little app I can pin to the taskbar, as im coding/self teaching full time atm.
The HTML, CSS and Javascript natively supported by browsers to develop Web Apps (You cannot run as a native app). The .EXE files are executable binary files of Windows. If you want to build Native Apps using HTML, CSS & JS, You have couple of options.
Electron JS
Electron JS is a amazing tool, To build cross-platform apps. You can develop your apps using HTML, CSS and JS and build it to any major platforms.
VS Code, Invision, MS Teams are built on electron Js
https://www.electronjs.org/
Use WebView on Native App
If you don't need to access any native function of the system, Then you can go with WebView. The web view is a feature to embed a website inside a native app. Most of the languages/frameworks have web-view support (Eg:- .Net).
If you are focusing on windows, Try .NET Web View
I'm working on a project for a friend, and it involves inserting a Java applet into an Electron HTML document for the user to interact with. Is there a way to do this?
I've already tried using node-jre to run it, and I am able to output the results into the console which is fine, but that doesn't give me an applet. I'm not too familiar with Java, but I understand some concepts of it.
Here's what I have using node-jre:
var output = jre.spawnSync(['client.jar']);
console.log(output);
I need the result to be <applet archive="file.jar"></applet> in the HTML file the user will view.
No, this isn't possible.
In the past, embedding a Java applet in a web page (or other web view) required the Java NPAPI plugin to be installed. This plugin was discontinued in Java 9, and browser engines no longer support NPAPI plugins, so there is no way to do this.
You will need to run your Java applet as a standalone application, or rewrite it in Javascript to run within an Electron app.
I would like to use angular.js for my Image Editing Tool in my website. Do I need node.js also?
I don't understand the scenario. If I don't need it, then when do we use both nodejs and angularjs together?
I feel your pain.
For someone new to Angular 2 development, I can feel the pain of having to learn server side technologies for something that is essentially a client side technology. From what I understand:
node.js is only used to manage the dependencies of an angular 2 application. If you can somehow manage to get those dependencies without using node.js, npm or jspm then you can run and develop your application offline. However, doing it manually will take an inexorable amount of time since you have to download files manually which may have other dependencies which will require other files to be downloaded again (yes I've been there). node.js or npm or jspm for that matter automates this process as well as taking all the necessary steps of configuring the files (jspm) so that whenever you use a particular dependency in your application, that particular dependency's other dependency will also be present in your system.
Some browsers, particularly Google Chrome restricts files loaded locally for security purposes so that certain HTML 5 technologies used by Angular 2 will produce an error when loaded using the file: protocol. So you need a server from which you can serve your application so that all the available HTML 5 technologies is available for Angular 2 to run.
node.js is also needed for the hot-module-reload capability for rapid application development since it provides a file watcher api to detect changes to source code.
But there is a way to develop Angular 2 application offline without node.js.
Remember when I said that if you can manage to get all the required dependencies, you can run and develop your application offline? If you can somehow find or create a package that has all the required dependencies your application will need, then you do not need npm or jspm to manage the dependencies for you.
For the file-access-restriction problem, you can load your project as an extension. Extensions have the ability to use all the available HTML 5 technologies as well as some powerful api's (not available even to applications served on a server), while at the same time being local to your development environment. So you do not need to fire a web server to access HTML 5 technologies if you serve your application as an extension.
For the hot-module-reload capability, you can approach it from the other way. Instead of having a file watcher in the web server to monitor changes to files in the local system, you can do it from the application itself. Since the application can fetch or xmlhttprequest resources that are needed by the application, you can periodically fetch or xmlhttprequest the resources your application needs and compare it to some cache. But how do you know which files to check? You can look for links within the page, script, of img. If you use SystemJS as the module loader, then you can use its registry to look for the files needed by your application but not loaded in the page, since it has been transpiled or something. While doing all this can be a performance drain to your system along with the added overhead of transpiling or preprocessing non-native code, this job can be outsourced to a web worker which will free up the main execution thread in the system for your application code.
Don't believe me? Here's proof.
The Angular in Chrome project on github contains a zipped package which contains the required dependencies needed to develop a minimal Angular 2 application (by minimal, I am referring to the Tour of Heroes tutorial referred on the quickstart page). So that if you are on a system not supported by node.js (yes there are, ChromeOS for instance) or just on a restricted system in which node.js just isn't available, all the required dependencies are available and you do not need npm or jspm to manage the required dependencies for you.
There is a proof of concept extension which serves the tour of heroes tutorial (the development files, typescript and all) locally as a chrome extension.
The extension also implements a hot-module-reload functionality by hooking into the hmr-primitives developed by alexis vincent for SystemJS. The hot-module-reload functionality is enabled by a single javascript file so that if this functionality is not needed or is taking up too much resources, then you can just remove the offending line of code.
But be warned though.
If you are using this system, then you need a way to update your development package as technology moves forward and it moves at a rapid pace (what with talk of Angular 3 when Angular 2 has just been released) or the technologies that you are using to develop your application may become obsolete or that somewhere along the line an api change may prevent your application from being functional in the future. You are also not guaranteed to have up-to-date repositories for the dependencies since these types of packages are maintained manually.
Bundling your application as a Chrome extension like in Angular in Chrome will introduce performance bottlenecks. Since code is transpiled and modules are lazy loaded, you lose the advances of JIT compilation and other performance enhancements that modern javascript engines use to optimize code run on the browser. However, what you lose in performance, you gain the flexibility to use the technology that you prefer to develop in. There is always a tradeoff. Moreover, the performance hit is only at the beginning as code is loaded. Once it has been loaded by the application, then the system will know how to implement the performance enhancements. When you distribute your application, you really need to compile the needed resources to take advantage of the performance enhancements of modern javascript engines.
The hot-module-reload capability is currently a hackish way of implementing a file watcher which uses common conventions for a project (temp1.ts, temp1.css, temp1.htm) since there is no way (I might be wrong on this) to get a definitive list of all the resources needed by the application but not loaded on the main page (the transpiled or pre-processed resources).
You don't need NodeJS for creating a client side image editing tool.
AngularJS is a web application framework, maintained by Google and the community, that assists with creating single-page applications, which consist of one HTML page with CSS and JavaScript on the client side.
But if someday you will want to upload and store those images on a server and make them accessible by multiple clients - then yes you will also need a server. This server could be made with NodeJS.
node.js is used to write Javascript on the server side.
angular.js is a client side framework.
You don't need node.js to use angular.js but, you can install npm (node package manager) to use some awesome tools that will make your life as an angular developer much easier.
For example: yoeman which is a great scaffolding tool.
There are many other tools available on npm here is a link to their site
Learn more about angular at the official angular website or at the angular youtube channel
No. Angular is used at the client side and Node for the server side.
They use to go together as the MEAN Stack but it's not necessary.
You don't need Node.JS for AngularJS to work. NodeJS is server side, AngularJS is client side.
If you are new to AngularJS, I'd suggest this tutorial AngularJS tutorial.
In the tutorial you will use NodeJS, you will understand why the two work together, but are not necessary.
It's hard to answer without knowing how your Imaging editing tool works. But to answer your question, no you do not need Node.js to use AngularJS.
Angular is a front-end javascript framework which operates in the clients web browser.
Node is a service which can execute javascript and is often used on a server maybe in replacement of PHP (like in MEAN stack).
Also, because Node is a service which can execute javascript it can be used in your local computer when developing Angular applications to do background tasks such as minifying css and javascript and performing tests.
So if your Imaging editing tool is developed in javascript and your application used Angular and Node (as a web server), the code could be executed on either client side or server side.
Have a read on MEAN stack to see where Node and Angular fit in. You don't even need Node at all but it's nice to develop all in the same language.
Reason for installing NodeJs
As a web browser such as Chrome, Firefox etc. understands only JavaScript, we have to transpile our Typescript to JavaScript. Therefore, the Typescript transpiler requires Node.js for generating the Typescript code to JavaScript.
Is it possible to list the files in a directory using only javascript? To clarify, I mean list the files on the server, not the files on the clients computer. For instance:
www.domain.com/files/
contains 4 images (.jpg)
Can I make an extra page (www.domain.com/files/list.html) that lists those 4 files using javascript?
No, Javascript doesn't have access to the filesystem. Server side Javascript is a whole different story but I guess you don't mean that.
Very late to this party, but my google search for this exact request led me here.
The answer is "not really", but I've found the frankenstein of hacks elsewhere: If +Indexes is (or can be) enabled in the .htaccess for the folder containing the files you want to list, then use XMLHTTPRequest with the folder name as the url (which will return an html page listing the files).
I don't know if you architecture allows it but ikf you can install and use node.js as its node API mentions, you can interact with the filesystem by requiring the fs module.
This is the environment Node.js relies on:
Node eventually wants to support all
POSIX operating systems (including
Windows with MinGW) but at the moment
it is only being tested on Linux,
Macintosh, and Solaris. The build
system requires Python 2.4 or better.
V8, on which Node is built, supports
only IA-32 and ARM processors. V8 is
included in the Node distribution. To
use TLS, OpenSSL are required. There
are no other dependencies.
You can run It side-by-side with another web app. and this will avoid blocking your web application if the interaction with the filesystem takes too long.
It is generally not a good idea to access client computer files via javascript for security reasons, however i suspect you can use the File System Object for that. I am not sure about browser-compatibility for that, it should work in IE only probably though.
You need to use server-side languages such as PHP, ASP.Net, JSP, etc
JavaScript runs inside a host environment. So if the host provides a facility to list files in this manner, then yes. But in the typical scenario where JavaScript is running in a browser with default configuration, no.
I want to create torrent files with a Firefox extension written using javascript.
Torrent file creators are currently available as desktop applications in anything but javascript.
May be it is also possible to find a decent torrent file spec in java, as azurious, an open source p2p client, is written in java.
Can somebody please give me hints, or maybe some specs, to achieve it using javascript.
Javascript is normally run within a browser in a "sandboxed" environment, where it can't for example create files. If you want to use Javascript in a standalone environment, such as jslibs, that's a very different proposition, and creating files becomes possible. So is your issue with Javascript per se, as your question and tagging indicate, or with the sandboxing browsers typically perform on it?