I am trying to generate an express skeleton, using the express generator. So it would be this:
$ npm install express-generator -g
However, it
Try running this command in command prompt:
express --help
It will give you the express generator help:
Usage: express [options] [dir]
Options:
-h, --help output usage information
--version output the version number
-e, --ejs add ejs engine support
--hbs add handlebars engine support
--pug add pug engine support
-H, --hogan add hogan.js engine support
--no-view generate without view engine
-v, --view <engine> add view <engine> support (ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)
-c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
--git add .gitignore
-f, --force force on non-empty directory
⚡ Source: https://expressjs.com/en/starter/generator.html
The above options give you the list of "view engines".
Now, simply type:
express -{your choice view engine}
express -e
:This sets the EJS engine as your view handler and removes jade. EJS has the look and feel of HTML with the added ability to inject values via their template system.
This generator seems to handle EJS templates. EJS is just HTML with the ability to insert variables. Well... Like a templating engine. But EJS is also the rendering engine for HTML.
In the app.js of the generator you can see this line (15):
app.set('view engine', '{views}');
So my guess is that if you select the EJS engine when installing, it will be good. As long as you put your html files in the specified folder (line 14, app.js):
app.set('views', path.join(__dirname, 'views'));
If you won't a view engine just type:
express --no-view
You can add an engine after or not working with server rendering.
You can also directly include your html file into your jade file
include ../../public/index.html
You can just delete the jade files and hook up your own template engine.
For example, I like using Handlebars.js. So in order to use that, in app.js
or server.js
or whatever the generator names the main file, you'd substitute the line:
app.set('view engine', 'jade');
with something along the lines of this (after installing and requiring handlebars, at least):
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
And every engine is as configurable as you want it o be.
You can check the documentation Express-Generator.
As you can see with express -h the view engine suported by express generator are (ejs|hbs|hjs|jade|pug|twig|vash), but by deafult jade is suported.
$ express -h
Usage: express [options][dir]
Options:
-h, --help output usage information
--version output the version number
-e, --ejs add ejs engine support
--hbs add handlebars engine support
--pug add pug engine support
-H, --hogan add hogan.js engine support
-v, --view <engine> add view <engine> support (ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)
-c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
--git add .gitignore
-f, --force force on non-empty directory