Before reading this post please read my previous article part1 .
here in CodeProject
you can download the code here
Assuming you are done reading the above article, we proceed with the website creation. Time to set up the express. First create a folder called, SityRoute which our website directory, any where you like, open a command prompt, go to the folder.
create a file named package.json insde the SityRoute folder, open the file copy the below content. I am giving you my package.json file so that things will be easy for you, if you are new to npm packages.
"start": "node ./bin/www"
after saving the above file under SityRoute directory, run the following command to set up the dependencies, if you are coming from .net site it is a nuget package kind of stuff. If you don’t know about package.json file then you got to do little bit of reading node npm packages and package.json file structure. Above dependencies json object lists out all the required dependencies in order for creation of our project.
it will give the following output at the end of the installation, shows the folder structure.
└── firstname.lastname@example.org (email@example.com)
├── firstname.lastname@example.org (email@example.com, firstname.lastname@example.org, email@example.com)
├── firstname.lastname@example.org (email@example.com)
├── firstname.lastname@example.org (email@example.com)
└── firstname.lastname@example.org (email@example.com)
├── firstname.lastname@example.org (email@example.com)
├── firstname.lastname@example.org (email@example.com)
└── firstname.lastname@example.org (email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org, email@example.com
.2, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org)
since we have mentioned express as our dependency in the above json file, it will install express version 3.4.8 along with other dependencies.
Now let us speed up the stuff. You can use express-generator to generate the scaffolding for our website, like it will create most of the ground work stuff for us like folder structures with some default hello world pages etc. Here is how to create it.
Run the following command to first install the express-generator.
$ npm install -g express-generator
it will install express-generator globally. We are good with express generator installation. Now we need to create a sample project in which we write our code, because we are going to re-use the same folder structure.
create a sample application
Once you have installed express generator run the following command from SityRoute directory.
express -c myapp
it will ask for confirmation that, destination directory is not empty, do you want to continue, say yes, following output will be generated.
destination is not empty, continue?
destination is not empty, continue? (yes or no) y
create : .
create : ./package.json
create : ./app.js
create : ./public
create : ./public/images
create : ./public/stylesheets
create : ./public/stylesheets/style.css
create : ./routes
create : ./routes/index.js
create : ./routes/user.js
create : ./views
create : ./views/index.jade
create : ./views/layout.jade
create : ./views/error.jade
create : ./bin
create : ./bin/www
$ cd . && npm install
run the app:
$ DEBUG=my-application ./bin/www
this creates a folder SityRoute with all the necessary default code in it, by default express generator sets the templating engine to jade engine. By now you should have folder structure something similar to below under SiteRoute folder.
Read next post here part3