Monday, January 11, 2016

Node Js Routes with Express

Install Express
a web framework





D:\MyProj\Nodjs>npm install express-generator -g

C:\Users\supreet_hadagali\AppData\Roaming\npm\express -> C:\Users\supreet_hadagali\AppData\Roaming\npm\node_mo

 

expressapp@1.0.0 C:\Users\supreet_hadagali\AppData\Roaming\npm

└─ express-generator@4.13.1

  commander@2.7.1

  │ └── graceful-readlink@1.0.1

  mkdirp@0.5.1

  │ └── minimist@0.0.8

  └── sorted-object@1.0.0

 

 

D:\MyProj\Nodjs>express -h

 

  Usage: express [options] [dir]

 

  Options:

 

    -h, --help          output usage information

    -V, --version       output the version number

    -e, --ejs           add ejs engine support (defaults to jade)

        --hbs           add handlebars engine support

    -H, --hogan         add hogan.js engine support

    -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

 

 

D:\MyProj\Nodjs> express myapp

 

   create : myapp

   create : myapp/package.json

   create : myapp/app.js

   create : myapp/public

   create : myapp/public/stylesheets

   create : myapp/public/stylesheets/style.css

   create : myapp/public/images

   create : myapp/views

   create : myapp/views/index.jade

   create : myapp/views/layout.jade

   create : myapp/views/error.jade

   create : myapp/public/javascripts

   create : myapp/routes

   create : myapp/routes/index.js

   create : myapp/routes/users.js

   create : myapp/bin

   create : myapp/bin/www

 

   install dependencies:

     > cd myapp && npm install

 

   run the app:

     > SET DEBUG=myapp:* & npm start

 

 

D:\MyProj\Nodjs>



Lets see how do we create a new page and navigate to that page


Create a jade file (its like html with view engine )

Modify the app.js file
here is the place you define your routes





run the server




No comments:

Post a Comment