Nodejs, Expressjs with EJS to Android doens't work in PhoneGap? - node.js

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.

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 deploy Express app on surge.sh

I have Express app, and I have index.ejs file instead of index.html and I can't deply it on surge (page not found). I use 'surge' command in project directory and than I go to the domain where it was published but my project doesn't run there. How should I deploy it? Please help me, I need to do it right now
Surge.sh is for serving static files (html,css,media..etc). Since ejs is a server side rendering template engine it can't be served using surge.sh.
Note: You can upload node apps to Heroku for hosting.
Since you have learned express, you can also learn Svelte. its a React/Vue like framework that compiles everything into a simple html/css/js site that you can then deploy to your favorite static hoster like surge.sh or even github pages
You can't deploy the Nodejs website on surge.sh as these services do not support server-side rendering like handlebars, ejs or pug, etc.
Vercel, netlify also do not support templating engines. However, you can use openode.io as an alternative, or maybe digitlocean under their app platform.
You may want to try to bundle the project and then use surge to publish it. I am not aware of any tool that can do that for you automatically, it might require manual setting.
Check this article:
https://morioh.com/p/c6e73ed575bb

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.

Reference compiled React javascript from Nodejs server

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?

Making files not accessible in node js

I'm using WebStrom to create a node js website.
1) What template of project should I choose (AngularJS, node express etc)? I do use angular-js but I also need a server side.
2) What are the best practices for the project structure?
3) How I make the server side js files not accessible from the browser? I created a few projects from the different templates and I managed to reach every single js file by writing its path in the browser.
Any help will be profoundly appreciated!
I would suggest using templating. I personally like using handlebars but there are many different options out there.
https://github.com/fixiecoder/node-express-handlebars-boilerplate
This is a link to a very basic node express application that uses handlebars templates. There are also many tutorials that you can use to learn more.
The line app.use(express.static(__dirname + '/public')); in the server.js file is what is used to specify a public folder that is the only thing that the browser will be able to access. Everything outside of this is private to the server.
The best thing you could do though it just do some basic tutorials from start to finish to understand how it all fits together.

Resources