Creating web applications with Node and Express
Express is a web framework which allows you to easily make web applications on node. I already wrote about writing a simple server with node, but this time I will focus more on the application structure.
Lets start by creating a folder for our app called app/ and put a file inside named package.json. This is a special file used to define node projects. You can find more information about it on node JSON documentation, in this example I’ll use just the basics:
1
2
3
4
5
6
7
8
{
"name": "app",
"description": "A simple sample app",
"version": "0.0.1",
"dependencies": {
"express": "3.x"
}
}
An important thing to mention is that this has to be a JSON file, so all the json attributes and values must be wrapped by double quotes (“). Most of the fields are just information about the project, but the dependencies attribute defines which packages my projects depends on. These packages will by default be downloaded from npmjs.com. We specified that we want the latest revision of version 3 of Express for our project.