Express Generator Without Jade
Asked Answered
A

7

25

I am trying to generate an express skeleton, using the express generator. So it would be this:

$ npm install express-generator -g

However, it adds a bunch of automatic jade files.

I was wondering if there was a way to get rid of those jade files and just using html with the express generator

Thanks!

Andryc answered 4/6, 2015 at 2:40 Comment(0)
C
15

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}


For example using 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.

Caning answered 11/1, 2016 at 9:38 Comment(0)
O
12

If you won't a view engine just type:

express --no-view

You can add an engine after or not working with server rendering.

Overscore answered 16/10, 2019 at 13:4 Comment(1)
This is what worked for me: npx express-generator someFolderName --no-viewIberia
S
3

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
Synonym answered 25/1, 2017 at 16:29 Comment(0)
M
2

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.

Marilla answered 4/6, 2015 at 2:57 Comment(0)
A
1

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'));
Apostolate answered 4/6, 2015 at 2:57 Comment(0)
D
1

You can also directly include your html file into your jade file

include ../../public/index.html
Dote answered 7/6, 2017 at 12:33 Comment(0)
M
0

Just change your express view engine jade to ejs/ or what ever you like.

app.set('view engine', 'jade');

change this line by -

app.set('view engine', 'ejs');
Melancholia answered 18/5, 2022 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.