In a server environment, I expect to write URL paths to query for data. In Electron, because I can use NodeJS in any part of the application with normal JavaScript, there seems to be no 'separation' between the two.
Where should most of the code be, especially if when using NodeJS? In the main.js file, or in the application's JavaScript file? Additionally, if a result from the NodeJS code is being written to the HTML dom, should it be written directly from the same code or stored and then written in normal JavaScript?
What is normal or good practice in Electron?
If you are new with electron and don't know where to start, I recommend to you to download this example and take a look to the reedme.txt and the code inside, it will lead you to the path to begin your app.
Take a look
Related
I'm fairly new to web development, but I've take a couple hands-on introductory courses where the basic structure of a website is you have an HTML file (or several ejs template files), a CSS file, and then you have something called a "server" file which is a JavaScript file, typically called app.js
I know that if I wanted to, I could include all my CSS inside the HTML file in <style> tags. My question is, should I have the need to do so, would it be possible for me to include the server code in <script> tags within a single HTML file?
Debating on whether or not I should put forth the effort to attempt to do so, but if it's generally problematic (note: I don't car about "best practice") for some reason such as it prevents you from working with certain packages/modules like EJS or Node.js then I will likely conclude that it doesn't make sense to try. As a novice web developer, I fear I am not aware of certain restrictions that I would likely run into if any (besides lack of module support).
would it be possible for me to include the server code in <script> tags within a single HTML file?
No.
Web browsers, which execute the scripts in webpages, do not provide JavaScript programs with the APIs required to run a server.
If you want to write a web server in JavaScript then you'll need to run it using a tool like Node.js and not a web browser.
No, you cannot put server-side code in HTML or in JS files that are sent to the client. Server-side code is code that is run on a server that you host, while client-side code is code that is run on the computer of the person who is visiting your webpage.
You can put client-side code in HTML <script> tags., and you can also include client-side code in separate JS files. The drawbacks are immense though, as:
Code highlighters won't be able to highlight your code and point out things like syntax errors as easily.
You won't be able to use tools like Babel and TypeScript, which input and output JS files.
You can't use NPM modules without a bundler like Webpack, which itself will output JS files.
Overall, there isn't really a good reason to use the <script> tag. It takes 2 extra seconds to just create another file for your JS, and it's more organized, more modularized and easier to use with external tools.
I have simple "to-do" application written in JavaScript and HTML. I don't even have CSS file, just have bit of in-line style in index.html file where I have linked my JavaScript file. No database or any other stuff needed. Simple app using vanilla JavaScript and HTML.
I have AWS free tier account and tried zipping .js and .html files and deploying to AWS Elastic Beanstalk but it's converting into node.js and keep looking for JSON file and deployment is unsuccessful.
Is this called JavaScript app or Node.js app in real world?
How do I deploy it in AWS?
As other have answered (without telling you how to do it) the solution is static web file hosting. You do not need to deploy your app to Elastic Beanstalk as your JavaScript are not executed on the server. They just need to be served to a client where they will execute in the client’s browser.
Amazon S3 is the most cost effective way to serve static HTML website.
The easiest way to setup S3 and deploy your application is to use amplify command line.
See the detailed procedure at https://aws-amplify.github.io/docs/cli/hosting
To learn more about Amazon S3 web hosting, please read this https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html
You are a bit confused on the two "terms" -> Javascript and NodeJS.
Javascript: is a high-level interpreted programming language;
NodeJS: is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser.
So, in your case, since you are not using any "backend", as suggested by other users you should use a simple web hosting.
Node.js is a Runtime Environment to run Javascript Code on the server i.e. on any machine with an operating system. So all Node.js apps will be Javascript apps but not all Javascript apps will be Nodejs apps.
In your case since you have an HTML file and your javascript file might be manipulating the DOM it would be classified as a Javascript app for the browser.
However if you have a javascript file which is not manipulating the DOM, you can run that on a Node.js environment.
I hope i have answered your first question, although i cant answer your second question at this moment.
JavaScript is a language.node.js is not a language or a special dialect of JavaScript - it's just a thingamabob that runs normal JavaScript.All browsers have JavaScript engines that run the JavaScript of web pages. Node.js is simply the V8 engine bundled with some libraries to do I/O and networking. so that you can use JavaScript outside of the browser, to create shell scripts, backend services or run on hardware.
I'm writing a single-page web-app custom data editor, which currently does not require any server side code to function.
The app generates a .tex file as output. The generated file uses memoir document class and does some complex formatting stuff that is hard to reproduce outside of a *TeX ecosystem.
I would like to let users download PDFs, not .tex files.
I would prefer to generate these PDFs in browser, client-side. I would settle for server-side generation though.
I tried texlive.js, but it lacks memoir. As for the server side, I would like to avoid setting a tex to pdf generation pipeline from scratch --- I feel that it would be a security nightmare.
Any advice?
Basically you just have to compile your own version of texlive.js.
The instructions are here. Just add the memoir package.
Server side renderers do exist. However I would recommend to auto-generate a VM for every run. Like CI-tools do it.
I would like to develop themes/plugins for WordPress based on React. To make it search engine friendly, I need it to be rendered initially on the server (serverside-rendering).
The only way to do this, as far as I know, is to use react-php-v8js, which requires the PECL V8js extension. This is a problem since I have no control over the platform on which these themes/plugins will be run.
Is there a way to make React and WordPress work together without having to install additional extensions? Perhaps by building/compiling React files into PHP?
There's an article that describes how to do this:
https://sebastiandedeyne.com/server-side-rendering-javascript-from-php/
But it's a fairly complex setup and it requires using composer. That can be difficult in Wordpress projects since Wordpress tends to completely eschew the modern php architecture.
If you're looking for a library to help with SSR in PHP:
https://github.com/spatie/server-side-rendering
Best of luck on it.
If you want your content to be indexed by search engine without js, you can print your minimal content using Wordpress, just the bare minimum + crucial meta tags, maybe localize some initial state for your react app to boot. A bare bone theme such http://underscores.me/ would be sufficient. When js is available, you can replace your whole WordPress generated content with React ones.
The ideal one is to have React generate the content for you. But it's hard until we can see that nodejs / PECL V8js extension available everywhere.
If you can at least install nodejs and launch a node process then it should be ok, although not so simple.
You would need to generate a ssr version of your assets and use it in a node process that would listen on a socket to write the html result..
In your controller you can create a socket to your node process (something like stream_socket_client(...)) and then you can send a dummy function written as a javascript string to that socket (something like stream_socket_sendto($sock, "getResultForMyWidget(someParams){...}")). That function would be evaluated in the node process that would return the response to the controller (the html response as a ReactDOMServer.renderToString from the component you want to render).
That's it for the big picture.
There is a symfony plugin that illustates it very clearly (see this github) and comes with a dummy server node process to illustrate how it handles the socket listening and eval of the incoming function and returns the html result. See also the example in the sandbox for a bigger picture and in depth implementation. You should be able to adapt it to wordpress.
So we're writing a full-text search framework MongoDb. MongoDB is pretty much javascript-native, so we wrote the javascript library first, and it works.
Now I'm trying to write a python framework for it, which will be partially in python, but partially use those same stored javascript functions - the javascript functions are an intrinsic part of the library. On the other hand, the javascript framework does not depend on python. since they are pretty intertwined it seems like it's worthwhile keeping them in the same repository.
I'm trying to work out a way of structuring the whole project to give the javascript and python frameworks equal status (maybe a ruby driver or whatever in the future?), but still allow the python library to install nicely.
Currently it looks like this: (simplified a little)
javascript/jstest/test1.js
javascript/mongo-fulltext/search.js
javascript/mongo-fulltext/util.js
python/docs/indext.rst
python/tests/search_test.py
python/tests/__init__.py
python/mongofulltextsearch/__init__.py
python/mongofulltextsearch/mongo_search.py
python/mongofulltextsearch/util.py
python/setup.py
I've skipped out a few files for simplicity, but you get the general idea; it' a pretty much standard python project... except that it depends critcally ona whole bunch of javascript which is stored in a sibling directory tree.
What's the preferred setup for dealing with this kind of thing when it comes to setuptools? I can work out how to use package_data etc to install data files that live inside my python project as per the setuptools docs.
The problem is if i want to use setuptools to install stuff, including the javascript files from outside the python code tree, and then also access them in a consistent way when I'm developing the python code and when it is easy_installed to someone's site.
Is that supported behaviour for setuptools? Should i be using paver or distutils2 or Distribute or something? (basic distutils is not an option; the whole reason I'm doing this is to enable requirements tracking) How should i be reading the contents of those files into python scripts?
The short answer is that none of the Python distribution tools is going to do what you want, the exact way you want it. Even if you use distutils' data_files feature, you're still going to have to have your javascript files copied into your Python project directory (i.e., somewhere under the same directory as your setup.py.)
Given that, you might as well just copy the .js files to your package (i.e. alongside mongofulltextsearch/init.py) as part of your build process, and use package_data or include_package_data=True.
(Or alternatively, you could possibly use symlinks, externals, or some such, if your revision control system supports those. I believe that when building source distributions, the Python distribution tools convert symlinks to real files. At least, you could give that a try.)