Reference compiled React javascript from Nodejs server - node.js

I have a React app that renders markup based on user input and I need to be able to render the markup the same way without a client. I've seen other people accomplish this by using Nodejs, is it possible to access React Components from Node given a reference to a compiled and minified Javascript file (this file is my React code bundled).

Yes, that is certainly possible with something like reactDOMServer. You can read more at: https://reactjs.org/docs/react-dom-server.html
What are you trying to do exactly? Are you trying to do it on a server? Or just on a command line? Are you using any bundlers like Webpack or Parcel?

Related

How do i convert MERN web app to desktop app?

I have created a simple billing web application using Node, Express, React and MongoDB
However i want to convert it into a Desktop application for local machines.
I know it is possible using electron, but i don't know how to do it.
Can anyone help me or provide with necessary resource?
you can use this boilerplate to get start a new project with react and electron.
Your build HTML file will act as the view file for your electron app.Which should be build by react-scripts.Use express server in separate file and use the server.
Handle requests just like you do in a MERN app.you only need to set the view to the bundled HTML file.

How to build a UI with typescript/NodeJS

I'm absolute new to this topic. I want to learn Typescript using NodeJS and have some simple questions. NodeJS is working with Javascript, as far as I know, but how do you get an UI? Do you have to create a HTML/CSS Webpage and run it with Typescript? How do you get Images, Options, Buttons in Typescript? How are they implemented in the Code? I found a lot of Tutorials, but they just return "Hello World" and I don't think I have to "write" the whole page in an output in Typescript.
NodeJS is pure server side javascript, you wont build the UI with it, you would serve the html/css/js to the client, and maybe create an API to communicate with the client.
I assume you dont need an example how to create a Node project, as you stated to have read some tutorials about it.
For starters, i would advise to go for NodeJS plus Expressjs on the server, then maybe start to serve simple static websites (like a handwritten 'index.html'). Expressjs makes development especially in the beginning a lot easier. Serving static files would just need something like
app.use(express.static('public'))
..in your server code. If you navigate then to e.g. localhost:3000/test/route, it would look for the /test/route/index.html in your public folder (which should be in your project root)
Then use a framework for client side development.
If you want to use Typescript for the development of the client side of the app, you might want to look into Angular. It is pretty tightly bound to Typescript, but the learning curve is pretty harsh if you are a beginner with this. Other client side frameworks that work well with Typecsript pretty much out-of-the-box or via cli are Vue.js and React, just as examples.

How to use JavaScript for front-end and Nodejs on backend

I have looked high and low and can’t find anything. I’m a little confused on Web Developement with Nodejs. I have built a simple static file server with pure Nodejs without any framework based on https://developer.mozilla.org/en-US/docs/Learn/Server-side/Node_server_without_framework. I’m able to serve my static .html files and .css files, but I can’t seem to figure out how to serve the .js files. Whenever I include my front-end JavaScript files in my server.js files I get errors like window is undefined or document is undefined. How does one go about developing dynamic websites with Nodesjs. I’m used to the PHP way of development. I just need help getting started with Node.js.

Haxe nodejs split js, insted of one js

How can I generate separated js files, when use Haxe nodejs target?
Now I have one big js file, but I wanted to compile each class to separated js files.
I found modular-js, but if I think good, this is not work for nodejs (because AMD), just for frontend js.
thanks
Have you seen hxgenjs? It claims to support Node.js:
The default configuration emits one javascript file per Haxe class, and uses CommonJS (require()) to link the dependencies. It should work out of the box with your current Node.js project, React Native project or any other CommonJS-compatible runtimes.

Nodejs, Expressjs with EJS to Android doens't work in PhoneGap?

I have a nodejs + expressjs app that needs to be converted to an android. A quick solution that we are thinking of is to use phonegap. The issue I am stuck with is all my files under view folder of the web app are ejs files.
When I try to upload my app to phonegap it says no index.html found in my .zip folder.
My question here is:
1. Should I separate the front end files from the node app? using html and pure js?
2. Is there a way I can render ejs files on to html files (something like import) so that I can convert existing web app into an android app?
3. Is there an option in phonegap to use ejs files instead of html files?
I am using https://build.phonegap.com/ for converting the app. Someone please help as I am stuck with this for a long time.
NodeJS/Express is for backend side, so, you can't package it to an Phonegap app.
In your Phonegap application you can only have HTML and JS (and others ressources like images...).
Should I separate the front end files from the node app?
Yes and then you have to create some webservices to get your data from backend to frontend.
Is there a way I can render ejs files on to html files
As far as I can read over internet, it's not recommanded to use EJS on frontend side...
Is there an option in phonegap to use ejs files instead of html files?
No, no way.
A phonegap app have a defined achitecture, please see/clone: https://github.com/phonegap/phonegap-start which give you a good exemple.
Hope this answer to your question.
Think this way:
You will run your app locally only, no server, no localhost, nothing. How can you render a template language as EJS locally?
There is no way to use EJS with Phonegap app, you should use only .html and .js files.

Resources