Richard WU
Richard WU

Reputation: 411

Express Generator Without Jade

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!

Upvotes: 25

Views: 19438

Answers (7)

Mahfuzur Rahman
Mahfuzur Rahman

Reputation: 1545

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');

Upvotes: 0

Kys3r
Kys3r

Reputation: 223

If you won't a view engine just type:

express --no-view

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

Upvotes: 12

Harsha Kasturi
Harsha Kasturi

Reputation: 243

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.

Upvotes: 16

havelino
havelino

Reputation: 390

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

Upvotes: 3

Priyanshu Chauhan
Priyanshu Chauhan

Reputation: 5535

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

include ../../public/index.html

Upvotes: 1

Julien Rodrigues
Julien Rodrigues

Reputation: 918

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'));

Upvotes: 1

gr3co
gr3co

Reputation: 893

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.

Upvotes: 2

Related Questions