Public directory not views directory in Node? And other Node questions

Why do my Node projects keep looking in the views folder when I strictly specify the public folder? Any advice appreciated! Also. I don’t want to use routing! Is this folder automatically generated despite the choice not to use views? Another thing my package.json file keeps getting replaced? Is this a Node thing? Doesn’t happen in any other type of Project such as Electron or Mobile…

Thanks to anyone offering advice, as always very appreciated. Trying to get to grips with setting up Node Projects right now and all seems to be a little bit, ummm, not quite sure… Frustrating I think is the word, especially for a new to Node noob like me…

:slight_smile:

1 Like

Should I change views to public in the below contained with package.json?

"nodemonConfig": {
"watch": [
  "app",
  "lib",
  "views",
  "extensions",
  "tmp/**/restart.txt"
],

Or (in server.js) change the root to public?

app.set('view options', { root: 'views', async: true });

Could these both not be usable definable in the Project settings if this is the case? Rather than defaults set by Wappler…? Neither are covered in the documentation from what I can locate here on the forum, and if they do control the root overriding other settings should this not be the case?

Sorry for all these questions. Maybe the answers could help others with future issues in the above regard.

Files stored in public have to be static(html, css, browser js, img, etc) as they are not processed at server and rather served directly.

The routing is 1:1 by defect in public unless there is a route specified that evaluates first.

So if you store page.html in /public/folder you will be able to access it at domain.com/folder/page unless you create a specific route matching domain.com/folder/page

1 Like

Thank you @JonL

Node is more of an initial head %&$# than mobile in Wappler… And that is saying something hahaha.

Now out of nowhere I’m getting restart.txt does not exist with no changes to settings or the server. Incredibly frustrating and really hit and miss right now. Sometimes it works, sometimes it doesn’t. Could drive a man to drink! :frowning:

Now after a Wappler restart no issues with the restart.txt, what is going on here?

No idea really.

restart.txt is a dummy file that triggers a server restart via nodemon. It is uploaded to target to trigger a server restart.

Nodemon monitors node apps thus the stupid name :joy:

I have it all working aside from database connections which I hope will be fixed in next weeks update (was hoping that was included yesterday but appears the solution still fails).

For NOW everything is working. My index.ejs file in the views directory is showing and working (correct?). For this moment have had enough of Node so will go back to work on another Project (thank all types of Lords and Gods it’s Friday).

Really appreciate your help @JonL

\awards JonL a new badge of most liked user on a Friday afternoon! :smiley:

The only way I can get it to work is by having the following in my app.js file:

    const server = require('./lib/server');
    var express = require('express');
    var app = express();
    var path = require('path');
    app.set('views', path.join(__dirname, 'views'));
    app.set('view engine', 'ejs');
    app.use('/nodeApp', express.static('public'));
    app.get('/nodeApp', (req, res) => {
        res.render('index', { title: 'nodeApp' });
    });
    app.listen();

Do you see any issues with the above Jon? A modification (only basic) on the following SO thread Answer:

Anytime buddy!

image

Let me add it to my anonymous forum resume to shove it somewhere.

2 Likes

Deep and dark where the sun has never shined! :smiley:

That’s a bold statement!

Have you gone through this?

Yes many many many many times. So many times its painful.

1 Like

I don’t use cpanel I am afraid but I don’t see anything wrong with your mod besides having to discard git changes with every update.

1 Like