Express and Express Generator

Asked

Viewed 243 times

0

I understood that the express Generator only creates Boilerplate for the project. But I didn’t understand very well which is the correct way to add it to the project

I need to install the 2, or only the Generator would be enough?

  1. create the project folder and dou npm init
  2. npm i express --save
  3. npm i express-Generator --save
  4. express nameDoApp

That’s not right, because now I have 2 package.json. Have problem node_modules stay out of project folder (test-gen)?

The file structure looks like this:

inserir a descrição da imagem aqui

1 answer

5


First you don’t need to create the folder and you don’t need to give npm init, just follow what the documentation says.

Install global Generator npm i express-generator -g

Check available options express -h

Create the project base with view engine ejs.

express --view=ejs myapp

After this command he will create a directory with the base of the project, after accessing and installing the generated dependencies.

npm install

View engine available

--view = (dust|ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)

If not to --view it creates with the jade view engine as default.

To create without defined view, use static html

express -no--view myapp

Example

To answer your question, you don’t add Generator to the project, it actually creates. And by your image there are no two package.json and only one other is lock that stores and locks the versions of each of the installed dependencies. The rest stay in the doc Express Generator

  • the other package.json is inside the test folder.

  • There, ta. Now I understand, that’s because you gave npm local before creating the project folder.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.