This document might be outdated relative to the documentation in English. For the latest updates, please refer to the documentation in English.

✖

Express dasturlar generatori

Dastur generatsiya qilish uchun express buyrug’idan foydalanishgiz mumkin, u dasturning asosiy qismini yaratib beradi.

Uni o’rnatish uchun quyidagi buyruqlardan foydalaning.

$ npm install express-generator -g

Qo’shimcha amallarda foydalanish uchun -h qo’shimchasini yozing:

$ 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
        --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

Masalan, quyidagi buyruq myapp nomi dasturni yaratadi.

$ express --view=pug myapp

   create : myapp
   create : myapp/package.json
   create : myapp/app.js
   create : myapp/public
   create : myapp/public/javascripts
   create : myapp/public/images
   create : myapp/routes
   create : myapp/routes/index.js
   create : myapp/routes/users.js
   create : myapp/public/stylesheets
   create : myapp/public/stylesheets/style.css
   create : myapp/views
   create : myapp/views/index.pug
   create : myapp/views/layout.pug
   create : myapp/views/error.pug
   create : myapp/bin
   create : myapp/bin/www

Keyin dasturning kerakli modullarni o’rnatish kerak bo’ladi:

$ cd myapp
$ npm install

Dasturni ishga tushurish (MacOS va Linux):

$ DEBUG=myapp ./bin/www

Windowsda esa, quyidagicha:

> set DEBUG=myapp & node .\bin\www

Undan keyin brauzerda http://localhost:3000/ manziligaa kirib dastur ishalayotganini tekshiring.

Generatsiya qilingan dasturning strukturasi quyidagicha bo’ladi.

.
├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
    ├── error.pug
    ├── index.pug
    └── layout.pug

7 directories, 9 files

Generator yordamida generatsiya qilingan struktra, Express dasturda yaratish mumkin bo’lgan strukturalardan bir usuli hisoblanadi. Siz bu strukturadan foydalanmasligingiz mumkin, o’zingizga kerakli ko’rinishda yaratishingiz mumkin.