How to use python in a JS based app - javascript

I have created an app using meteor.js framework. I need to run some python code for some important data crunching that will be used in the app. How can I do that? I am really new to Javascript and cant figure this out. I will be running python code on server. All I need is, as soon as I click a particular button, a piece of python code gets compiled.

You'll need to expose your Python code over some sort of API. Since your Python is "running on the server" as you mentioned.
The fastest way I can think of doing it is to setup an AWS Lambda function (https://aws.amazon.com/lambda/), then expose it as an API route using AWS API Gateway(https://aws.amazon.com/api-gateway/).
Once your "number crunching" is completed, you'll need to return the relevant variables back to your client app. JSON is probably a good choice for this.

Related

Is possible a web app that execute Pandas/Scipy/Numpy in the client?

I wrote a data processing program in python. My program takes some input data and transforms it using python libraries such as PYTHON-MIP, Numpy, Scipy, Pandas, etc. I want to build a graphical interface for this program and I would like it to be web to display graphs with libraries like Chart JS. I know how to build this app by separating the frontend and the backend. But I would like the processing to run on the client. That is, I want an application without a backend. I don't know what options I have.
The browser (the "client") is not able to run python code. It will have to run on the server side.
With web assembly is possible execute python in the client. The best option is pyodide, that able the numpy, scipy, scikitlearn, pandas, etc. Pyodide

Can I call ANOTHER JS FILE and return DATA (here: string) from it with JQUERY AJAX?

I'm currently experimenting around with a webframework (ZURB Foundation 6.4) and Im just figuring out how to implement my own JS.
Because Im unfortunately working at an office machine without admin privileges, its a huge pain in the a** to get some apache/php server running to test out the implementation of JQUERY AJAX calls.
Therefore, I just want to test the front-end implementation by calling another JS file with jquery ajax. This file shall just return a string. This is merely to have some dumb file to call via AJAX and return data from it, so I can figure out how to implement this later on when I have an actual backend to work with.
Is this possible? I already tried to call a JS file but it doesnt seem to work. I dont get any data returned from the file. Since the implementation of the ajax call is a bit different from how I would normally do it, I find it hard to figure out whether Im doing something wrong in writing out the call, or if its just not possible to call another JS File via jquery AJAX.
I'd say that you can't call another local file without uploading it to the server.
If you are using npm you can try for testing purposes fully worked and easy to use Json Server (google it).
Created with <3 for front-end developers who need a quick back-end for
prototyping and mocking.

ReactJS vs NodeJS - Why do I need to create both?

I understand that React is frontend, and NodeJS is the backend that allows Javascript code to function outside of a browser. What I don't understand (and this is after following tutorials online on setting up a React project and a NodeJS project) is why I have to create an instance of each.
For example, in my React project, I managed to create a website. But because I needed a backend, I decided to use NodeJS. But I'm doing NodeJS tutorials, and I can create a website using NodeJS too. I'm confused because right now, it's appearing to be that React and NodeJS do the SAME THING.
I have never worked with NodeJS before so I am a bit confused. I was under the impression that I would just use NodeJS to host the backend, but after seeing that I'm literally having to create an entire website with NodeJS, I don't understand how I'm supposed to use React and NodeJS together.
How do the two, React and NodeJS, integrate together to create a fully-functioning web app? I have yet to see something online that clearly breaks down how the two interact.
React is front-end library. It provides great tooling for creatiing user interfaces. And it creates a single page application. Which means when you open a react app. It does not reload and its really fast.
While you could also use nodejs and something like handlebars to create a website. But that website would be rendered on server and then served to the user. But its alot more than that. There are a lot of things that you want to do on the server. Like authentication. You want that part to be secure. So you keep it on the server.
Now the answer to the final part of your question.
For a fully functional app. You would use react to create user interfaces. And nodejs for creating an API which your react app will call.
NodeJS is not just regular javascript, it is a javascript runtime that sits on top of a C++ engine called V8, provided by Google. Node executes outside the browser, whereas React / Vue / Angular / etc are in-browser javascript frameworks.
React is a whole separate animal; it is a framework that renders its own DOM in the browser. It is a javascript engine that is configured to optimize DOM manipulation.
While the development pattern of frontend and backend appear similar, they are doing different things. React is handling component lifecycles, applying dynamic style rules, processing in-browser data, and making API calls. Node is handling requests from the browser, coordinating access to the server's file system, managing network I-O, performing cryptographic evaluation, etc. Because of these different responsibilities, Node makes use of different dependencies (read: node modules) than a frontend framework.
Ultimately, Node and React communicate through HTTP calls (or, less frequently, through a WebSocket or SOAP protocol).
It would behoove you to read about how node works under the hood.
NodeJS is just a runtime that allows you to run javascript code outside of the browser.
In order to compile and transpile the react JS app, they use webpack and other tools which runs over NodeJS.
NodeJS will serve as your backend, whereas ReactJS will create the interface/UI where you can actually manipulate your server (nodeJS). So first you'll write your NodeJS server or API. You don't need to use ReactJS to create a frontend that would interact with your node server, like you said you can use NodeJS to create your views as well through a different library. ReactJS is just one choice of many for the front end of your NodeJS app.
The point is that react and any other SPA library is working on a client-side (browser).
React fetch and consume the data from the server API.
You don't need to use Node.js for building API. You can use various frameworks based on the technology you prefer.
If you are not familiar with the Back End, you can use https://www.npmjs.com/package/http-server to have a fake API service and can build the Front End part with it.
NodeJS is a javascript framework that allows you to create a server to serve up websites using Express or the built in libraries. It also is capable of building a website with just NodeJS.
You can take advantage of the ability to do server side rendering with a NodeJS server.
https://reactjs.org/docs/react-dom-server.html
There is a ReactJS framework called NextJS tha has server side rendering of ReactJS component.
https://nextjs.org/#features
You could potentially have some areas of your website that are built solely with NodeJS and other pages that use ReactJS and a NodeJS backend. But it is cleaner to use ReactJS for the front-end and NodeJS for the backend.

SqlTableDependency for nodejs?

in my application in node I run a query every 30 seconds to get data from my sql server database.
However I want my app to be real time, i saw there is something that is called "SqlTableDependency" in asp.net that do exactly what I need.
The package "SqlTableDependency" listens to the database and send notifications whenever the table change.
I want to know if there is a package in node that does anything similar.
Thank you for the help!
you can go for EDGE.js this link which is a bridge between node and c#. Basically you can execute c# code through node code by importing a module called edge.
You can get more tutorial stuff on this link.
I am also looking for a complete replacement of c#.

Call WCF service from JavaScript HTML within service

I currently have a WCF service that operates on a database. I'd like to be able to use JavaScript (specifically AngularJS) to call the service methods and display them in a webpage.
I know this can be done using a separate ASP.NET client application that uses the service, but I'd like to have the JavaScript/HTML be a part of the WCF service project. Ideally, I'd like the user to see my webpage when running the service, rather than something like this: https://pieterderycke.files.wordpress.com/2011/01/service-page-in-internet-explorer.png, but I have no idea where to start.
Where must I put my JS/HTML files in the project and how do I reference them from the WCF service? Does something need to be done to expose the service to the JS/HTML files? Thanks in advance!
It's actually rather simple, really just a matter of adding the files to your project. You just need to make sure the references within the JavaScript/HTML files all still point to the right spot. If you're using AngularJS specifically, add that to the project first, then add your custom files.
Also, if you're looking to show an HTML file when running the service in Visual Studio, have a look here: Displaying web page when running WCF service.

Categories