I'm a novice with express
and mustache
, but I do not understand the error:
index.js
const join = require( 'path' ).join;
const EX = require( 'express' );
const MiniModule = require( './mini' );
var app = EX( );
app.engine( 'must', require( 'mustache-express4' ) );
app.set( 'views', join( __dirname, 'views' ) );
app.set( 'view engine', 'must' );
app.use( MiniModule );
app.listen( 8080 );
and mini.js
const EX = require( 'express' );
var Router = EX.Router( );
Router.get( '/login.html', function( req, res ) {
res.render( 'login.must', { title: 'Prueba de mustache' } );
} );
module.exports = Router;
The template I try to render is very simple:
File login.must
:
<html>
<head><title>{{title}}</title></head>
<body></body>
</html>
The directory hierarchy of the project is as follows:
Proyecto/
+-node_modules/
| +- ...
+-src/
+-index.js
+-mini.js
+-views/
+-login.must
When executing index.js
, it does not show any error. The server boots and listens on port 8080
.
But ... as soon as I try to access, with the browser, to
localhost:8080/login.html
I get the following error:
fs.js: 952
return binding.readdir (pathModule._makeLong (path), options.encoding);
------------------- ^
TypeError: path must be a string or Buffer
at TypeError (native)
at Object.fs.readdirSync (fs.js: 952: 18)
at loadPartials (Project / node_modules / mustache-express4 / lib / mustache-express.js: 11: 14)
at Project / node_modules / mustache-express4 / lib / mustache-express.js: 28: 63
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js: 446: 3)
- What am I doing wrong?
- How do I solve it?