Is it possible to use Jade in a regular web app without running on Node js? The question may sound crazy as Jade engine is written in node but wanted to find out if it can can be used oustide of Node.
So, it all depends what you really want.
You can compile a function to jade directly, through the CLI :
jade -w index.jade (-w is "watch for change", auto-recompiles)
or, if you use another language, you may be interested in other implementations :
PHP (I think you may find forks maintained)
Scala
Ruby
Python
Java
Yes, you just need to somehow get the jade compiler to run at the right time. You could accomplish that manually though a watcher script or with a build environment like nodefront.
Related
Let's say that I have a build up MEAN application written in JS, and I want to keep it but add some classes/interfaces using TS (I want to do this because I want interfaces) and use it in my controllers to communicate with my backend. Is it possible? If yes, how do i do it?
Thanks in advance!
Since TypeScript is a superset of javascript all JS code will work in typescript BUT you need to change the file extensions from .js to .ts
Furthermore, all typescript code must be compiled back to javascript before run. which means a typescript compiler has to be installed and configured.
That was my answer to your question.
As a piece of advice since you are building with MEAN stack then you are used to Angular way of structuring code.
If that is the case then you can build your server the same way with TypeScript using a framework called NestJS which is very very similar to Angular:
https://nestjs.com
I observe that I cannot instantiate a child process in Vue.js. Is there any way to execute a python script in Vue.js (2.x) ?
In theory you can add pyscript, see: https://pyscript.net/
Vue is strictly a client-side framework, except when being used from Nuxt.js. If you're not using Nuxt, you would need a server of some sort (whether Python or Node or something else), and that could call a python script when needed. If you are using Nuxt, you could call Node's child_process.spawn (or exec, or spawnSync or execSync) to run a Python script (see these docs). One last alternative would be transpiling your python to JS or compiling it to WebAssembly, but it sounds like what you want to do is run a server-side script, so that wouldn't work for you. My recommendation would be to serve your Vue app from a Python server (or some other server that can exec Python).
If I understand correctly, with the release of Kotlin 1.1, we can set JavaScript as a compile target for full compilation to JavaScript of Kotlin projects. Is it possible (or feasible) to write an entire Node.js application, such as an express webserver, using only Kotlin code?
As this question suggests, we can import Node modules into Kotlin classes:
external fun require(module: String): dynamic
val express = require('express')
...which seems like I can create an application using:
val app = express()
Is this the Kotlin way to set up an express application? Or should I declare a class as described in the docs:
#JsModule("express")
external class Express { ... }
What is the canonical way to set up a Kotlin project for Node.js application development? Is Kotlin's JavaScript interoperability robust enough to continue down this path, or will it be more trouble than it's worth?
Technically speaking, yes, provided the claim by Kotlin that:
You can use Kotlin to interact with server-side JavaScript such as node.js
Is correct, and the transpilation of Kotlin -> JS is reliable enough to be able to predict what JS is coming out, then you could write a Node app in Kotlin, much as you can write them in TypeScript.
I suspect, personally, that you'd find it difficult, buggy, and rather short on support, but it might make a good academic exercise...maybe.
Yes, it's possible https://kotlinlang.org/docs/reference/js-project-setup.html
But, NIO was the biggest reason to use NodeJS instead of any language to build a backend solution. Now, with reactive first class support you can have a stack like Kotlin + Spring Reactive + Coroutines + R2DBC and build a simple micro service or any full enterprise solution.
I have written a self contained angular js module using browserify in order to make use of the commonJS/Node style syntax.
The module works fantastic when tested by itself, so I then use gulp to minify and host that on GitHub.
I've then imported that into another app that is also using browserify. When I run browserify it seems to try and rebrowserify the module and causes no end of problems.
I believe this is because the module requires angular and jquery and qtip2. So it's obviously trying to re parse these.
Is there a standard to not parse modules, or is there a way to exclude the browserifying of the modules? Or is it best to not include things like angular and jquery within your modules? I was trying to make them perfectly stand alone, maybe that's unwise?
Many thanks!
I would suggest providing both options, if it is important for you to have a standalone version that includes angular. This will provide people using your code with a total of three ways of using your code: Using the standalone version, the version that only includes the module, and cloning the repository directly and including the source files as part their build process.
I generally use the third option, but people who don't have build processes will likely prefer the first or second.
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.