I want to create a Javascript app but I want to do that only using Javascript.
Because the node js is framework and I don't want to use any framework,
can I create a Javascript app without a browser and without any framework?
Only using Javascript?
In order to run a javascript application, you need a javascript runtime, in the end you will have to install some, however, you can try something different like live-server from npm
You could install nodejs runtime environment and run your code in cmd explained here. https://www.geeksforgeeks.org/how-do-you-run-javascript-script-through-the-terminal/#:~:text=You%20can%20Run%20your%20JavaScript,Environment%20Download%20and%20Download%20it.
Node js is actually not a framework or a library, but a runtime environment, based on Chrome's V8 JavaScript engine. I suggest you use it.
Just install, type in console(powershell, bash, etc.):
node file.js
and I will run your app.
Related
I want to create a Javascript (using Electron) app, but I want this app to be run and executed with terminal commands, like how you run git, is there a way to accomplish this?
I know that python and ruby are better languages for this purpose but I have a reason to use electron.
For non-GUI applications, you can just use node.js directly. If you want to make a TUI, you can use node.js + a module like blessed (and possibly blessed-contrib).
Electron is basically Chromium browser with tabs and all that stuff stripped out, plus a pile of tools to work with the user's desktop environment added in. It lets you use add HTML and CSS to a Node.JS application to create a GUI.
If all you need is a terminal command, Electron is completely unnecessary.
Here's a little pile of links to help you get started creating your command line app:
Writing command line applications in Node (Free Code Camp)
Scripting with Node (Atlassian)
Node.js with Commander npm module would work very well for your requirement.
I often develop in Python and sometimes find it useful to type python at the terminal prompt and drop into a Python shell where I can import various modules and test some behavior. Node.js has similar functionality if I type node at the command line.
I'd like to do the same now that I'm developing with Meteor. How can I get to a shell prompt where all the packages I have added with meteor add are loaded and ready for me to play with?
Just install node-inspector and then you can easily use the node-debug command to run node-debug mrt. That should open a debugger console.
You can then just drop a debugger; keyword onto a line anywhere in your code to drop into a REPL like setting.
As of recently, meteor shell will give you a REPL into the server process.
Of course, you know this #JoshOwens, I think I heard about this on your podcast :)
Node.js and python are both interpreters.
Meteor is a application framework build upon node.js. So testing out code in the way you mentioned is impossible.
You can however use the chrome debugging tools to run client side code within your meteor application.
Executing server side code to see what it does is a bit harder but also not impossible. Best way would probaply to setup nodejs remote debugging and using the debugger. See: Meteor debugging setup
Is there any software that I can use to compile nodejs program?
The reason I want to compile nodejs code is to make it safely distributable.
For example for a desktop application,etc.
And also I want to know whether nodejs will execute faster if compiled as it is asynchronous already?
Javascript is not a compiled language and Node.js is Javascript. It will be executed and interpreted at runtime. You can process your javascript with tool like grunt.js for example lint-test and uglify it, but be careful so that do not break the npm system since it is based on certain conventions.
To package your javascript for distribution in the node.js context build an npm module.
https://www.npmjs.org/doc/developers.html
For distributing javascript to the desktop client: Remember it's Javascript an it need to be executed in the Javascript VM. So to have some UI you need to run it in the browser or you need to have some webkit compiled dll to run your code...
something like this...
http://www.tidesdk.org/
You can also use: http://github.com/rogerwang/node-webkit (Thanks to #edi9999)
There is no way to do that with v8, it has only JIT option. It possible to make a "snapshot" with v8, but it's not exactly the same as compilation and node.js doesn't have support for this feature (also it might produce slower code). Also all your code will be available with toString() of functions.
You might be interested in JXcore project. It is a fork of node and as far as I know has some solution to code protection. Also one of the project goals is to develop javascript-to-LLVM compiler. Of course it can't have full support for ES specification (eval, new Function etc).
There's no way to 'compile' a nodejs program, as the javascript is interpreted at run time.
However, if you want to protect your code, you could maybe use something like Uglify JS to make the javascript less readable. However, this won't hinder people to change around your code.
The closest you might get to acheiving your goal is to create a self-executing Javascript bytecode wrapper.
A project that does this is pkg
It somehow creates a self-contained binary executable from Javascript, including module dependencies and asset files and produces a self-contained executable.
Installation and use is easy:
$ npm install -g pkg
$ pkg index.js -o my-program
$ ./my-program
It seems the resulting binary contains nodejs bytecode. It appears that you can cross-compile.
Is it possible to use the dart:js library without having a html file to load the js files but some alternative way of loading the javascripts in the context?
I need this for a command-line app, so having a html file makes no sense
When you run a command line app in the DartVM there is no Javascript VM, so you cannot use Javascript libraries.
However depending on your use case, you could run your javascript code with node.js, and communicate with the DartVM using sockets.
Perhaps add some more details about your specific use case.
Update:
To run lessc from Dart, first install node.js.
Then Install lessc:
npm install -g less
lessc styles.less styles.css
You can then call lessc from Dart using dart:io Process.run().
Is there a way to run a JavaScript file directly in NetBeans or Eclipse?
I feel it's time consuming to fire up a terminal, browse to that file and run it with node all the time.
Another NetBeans Node.js plugin with a Node.js project type and npm integration (I am the author of it) is described in NetBeans Tools for Node.js
Yes, you can debug using Rhino in "Run As" without leaving Eclipse:
http://wiki.eclipse.org/JSDT/Debug
http://www.eclipse.org/webtools/jsdt/debug/
If you'd like to debug it remotely on a Node.js instance, you can use:
https://github.com/ry/node/wiki/Using-Eclipse-as-Node-Applications-Debugger
If you'd like to remote debug a Chrome/Chromium browser:
http://code.google.com/p/chromedevtools/wiki/EclipseDebugger
The latter two options will use V8, which is Google's JS engine behind Chrome, which has also been implemented in Node.js. The first option will use Rhino, which is Mozilla's JS engine.
Yes, you can run a JavaScript file directly from the NetBeans IDE with the Node.js plugin:
Download NodeJS plugin from netbeans.org