ExpressJS - Scaffolding
Scaffolding allows us to easily create a skeleton for a web application. We manually create our public directory, add middleware, create separate route files, etc. A scaffolding tool sets up all these things for us so that we can directly get started with building our application.
We can use express-generator to create application skeleton easily −
npx install express-generator
npx is available node 8.2.0 onwards. In case of earlier version, we can use npm as follows:
npm install -g express-generator express
Once express-generator is installed, then run the command as follows and it will create a skeleton project as shown below−
E:\Dev\express-apps>npx express-generator
warning: the default view engine will not be jade in future releases
warning: use `--view=jade' or `--help' for additional options
create : public\
create : public\javascripts\
create : public\images\
create : public\stylesheets\
create : public\stylesheets\style.css
create : routes\
create : routes\index.js
create : routes\users.js
create : views\
create : views\error.jade
create : views\index.jade
create : views\layout.jade
create : app.js
create : package.json
create : bin\
create : bin\www
install dependencies:
> npm install
run the app:
> SET DEBUG=express-apps:* & npm start
Now to install dependencies, run following command.
E:\Dev\express-apps>npm install
This will install the relevant dependencies and project is ready to start development with.
Advertisements
