Render an html on the node with js

0

I can route on the node where it calls an html page, however the html page has a .js file and when it is called from the error of not finding the JS file.

Can anyone help me?

Structure:

main folder: project

Sub folders: config, js, views

inside config: config.js within js: request.js within views: index.html

config.js:

var express = require('express');
var port = 3000;
var app = express();
var bodyParser = require('body-parser');


app.use(bodyParser.urlencoded({extend : true}));
app.use(bodyParser.json());
app.listen(port);


app.set('views', './views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'ejs');
app.use('/public', express.static(__dirname + '/views/'));

module.exports.express = function(){
    return app;
}

app.js (it's located in the main folder):

var app = require('./config/config.js').express();
app.get('/',function(req,res){

  res.render('index.html');
});
    
asked by anonymous 24.09.2017 / 01:54

1 answer

0

Place config.js in the root folder, so it is easier to keep the project, and the application files in the app folder (you can choose any name), index.html can be isolated, other templates can be allocated in the views

  

config.js

     

app

     
    

index.html

         

js > request.js

         

views > otherTelas.html

  

And find the index with express

var express = require('express');
var app = express();
app.use(express.static(__dirname + '/app'));
    
24.09.2017 / 02:20