NodeJS Express GetStarted
NodeJS Express
Express is web framework like Rails.
The latest version(2015/04/) is 4.x. 3.x and 4.x are different.
Install Express4
If you don’t have node in your env. Please install node first.
In Mac case, this is an entry(NodeJS Get started in Mac OS X)
Install express
We need 2 packages
npm install -g express npm install -g express-generator
Create Express Application
To create Express4 Application Template, we can use express-generator
express application
application is your application name
By default, express application is Jade template.
If you want to use EJS, add -e option
express -e application
IDE
Eclipse and Nodejs plugin, WebStorm etc…
Debug and Start application from IDE, and set break point. Those are the points.
In my opinion, WebStorm is very good. WebStorm is not free.
I tried trial version first(30days).
WebStrom has import feature, and you can import express template application project in your WebStrom
Start Application
By default, Express4 application doesn’t have any server listen parts.
We need to add listen part.
Please add following codes before module.exports.
// Start app.listen(3000); module.exports = app;
To start application, type command
node app.js
app.js is main codes in Express.
Directory Structure
Application |- bin | |- www |- node_moduels : NodeJS modules |- public : Web public directory(images, css, javascript etc...) |- images |- javascripts |- stylesheets |- routes : Routing files |- index.js |- user.js |- views |- index.jade(.ejs) |- app.js : main codes |- package.json : package file
This is main parts of express codes.
public is public directory. You can put static contents such as images, javascripts, css etc…
package.json is dependency node modules management file. This is like Gemfile in Rails
views is view file directory. You can put jade, ejs, view file in here.
You can access view file in express application
node_modules is dependencies module directory. We saved modules in here.
routes is route decision directory. You write route and route action in here.
How to learn?
Express Web page is helpful for you(here).