Is it possible to use a python script in Vue.js? - javascript

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).

Related

How can I run Javascript without a browser or node js?

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.

How to run AngularJS2 application without Node server

Is it possible to run an Angular 2 application in browser without using NodeJS as a server. I am not sure, but if i understand correctly the newest browsers are able to compile/"understand" the TypeScript code so i don't have to use any third part js lib to compile it into plain javascript?
I would like to create an application using 100% Angular 2 on frontend and for the
backend REST API using Ruby On Rails, without using Rails's page rendering, sessions etc..
I am little confused about it how does Angular2 work/run behind the scenes... How i should configure my Angular2 application to use it without NodeJS?
I think you're mixing up some technologies here.
Server
You can run an Angular app on any server that can host static files. There is nothing special about node. So yes, you can use a ruby. Or an Apache, nginx, lighttpd etc.
The reason for this is that JavaScript is run on the client side. The server's response is only to deliver the JS/HTML/CSS files to the client that is visiting your site.
TypeScript
If you're writing an application with TypeScript you need to transpile it to JavaScript before any browser understands it. You can do this (1) before you're deploying your app to the server or (2) use a library like System.js that will transpile TypeScript on the fly.
While (2) is definitely an option and the Angular CLI used it until recently, (1) is in my opinion the better option. Angular CLI switched to (1) and is now using webpack. Webpack is transpiling and bundling your app before it is hosted on a server.
Hope I could clear things up a bit for you.
TL;DR
If you use TypeScript with Angular 2, you only need Node during development:
DEV: NodeJS is used to transpile .ts files to .js files.
PROD: Generated .js files are used inside the browser, NodeJS is not required anymore, except if you also happen use it in the backend.
NOTE: If you only use plain JS in development you do not even need Node
You can use any server side technology including Asp.Net Core, Node.Js, PHP to server the js, html and css content.
While building the application in the IDE, the Node.js transpile the .ts files into .js file.

How to run a ReactApp in Apache Tomcat?

I'm able to run any ReactApp only on Nodejs server, but not on a Tomcat server.
Some Qs:
React is purely client side rendered library, and why it requires Nodejs (which is server based)? Why React official Tut recommends Nodejs?
Is it true that Tomcat is for running pure Java applications, and Nodejs for pure JavaScript applications?
I tried to run a sample ReactApplication with few containers in Apache Tomcat, by including the Reactjs include files. But, I get a blank screen. Inspect element shows the non rendered JS source.
Update 1:
If yes for Q1, then Here's a simple React ready application (with all dependencies included) which is easy to run in Nodejs using NPM. How can I run the same app in Tomcat? Can I able to create Web ARchive using this?
1.React is purely client side rendered library, and why it requires Nodejs (which is server based)? Why React official Tut recommends Nodejs?
React is a client-side library but it requires NodeJs for below reasons :
- React uses JSX syntax which browsers doesn't understand and hence it needs to convert into a javascript code that browsers can understand, Babel will do that. Babel needs NodeJs and with the configuration you can convert JSX, ES6 code into ES 5 which browsers can understand
- You may also need node js server if you are using React on server side but this is optional
The sample that you have given needs to transpile into ES 5 code using web-pack which uses Babel. WebPack and Babel both need node js. Hence you need NodeJs.
I don't know what you hide under ReactApp.
But if you use React in client Side you don't need Nodejs server to run it. You can you Nodejs to build it, there is tools to simplify the work. So your ReactApp will be only an HTML page with some js dependencies. Apache or Tomcat can serve it, but for Tomcat you have to bundle it as WAR I think.
But you need rest endpoint to do some stuff, and you can do that with lot of technologies include java and tomcat.
YES

Is it possible to load twilio.js library with webpack?

What i need is a way to bundle all my javascript dependencies into one javascript file with Webpack (Just like with socket.io-client), but i can't do that with twilio.js.
I can see that the latest of twilio.js is listed here.:
https://www.twilio.com/docs/client/twilio-js as a script tag to:
//static.twilio.com/libs/twiliojs/1.2/twilio.min.js
But this is just a loader script for building the real twilio.js library here:
https://static.twilio.com/libs/twiliojs/refs/82278dd/twilio.min.js
And none of these supports Webpack.
https://github.com/twilio/twilio-node also exsistes, but this is for node.js only - not just plain client side javascript.
So my question is, is there a way to require the twilio.js library with Webpack ?
This answer is for Twilio.js client version 1.3.16 (script file, documentation).
The Twilio codebase is pretty bad. They don't publish their code to npm, and simply loading the twilio.js file from their CDN has side effects, including reading from window and looping through all script tags on the page. This means, even with the below answer, the client code can't be loaded in node, blocking server side rendering and testing, etc.
I published the package to npm as a mirror of the code, but it's not straightforward to use. Webpack can't correctly handle whatever bogus require structure they have set up. First, install:
npm install --save twilio-client-mirror
Then to use, require as normal:
import * as loadTwilio from 'twilio-client-mirror';
However, you can't actually use the loadTwilio object. You have to reference the global Twilio object, injected by the script:
const Twilio = window.Twilio;
Twilio.Device.setup(token);
...
This is a first attempt I made to try to include this flaky code inside a modern codebase. Hopefully with the coming 1.4 beta they will address these issues.
I know this is late, but I, too, just wrestled with this issue. Being new to Node, TypeScript and Webpack, I failed to understand that Webpack should be used for client-side scripts, while the Twilio-node library is a server-side library (as discussed loosely here). In other words, you shouldn't use require('twilio') in any client-side scripts...only Node scripts.
I had success with the following:
Add <script type="text/javascript" src="//static.twilio.com/libs/twiliojs/1.2/twilio.min.js"></script> to my main .html page
Use var twilio = require('twilio'); inside of a Node (server) script...not in client-side JavaScript (for example, add the Twilio calls inside of API methods, which can be created using a framework such as Express)
If you happen to be using TypeScript for Node scripting, use a transpiler such as the native TypeScript transpiler tsc (easy to do from a command line). If using JavaScript, use GulpJS (my fave) or GruntJS to help you consolidate and even run your Node server-side scripts
Use Webpack for anything else
Again, I'm new to this, so I'm open to input or corrections if I've stated anything incorrectly.

Jade lang in a regular web app without node

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.

Categories