Introduction to express
express could facilitate development of both Web server and API server, it is a packaged module of node.js http module
Simple use of express
Get and post in express
Static server in express
app.use(express.static('public'))
to declare public as a source for static server, express will look for css, html and js files under this directory and /public will not appear in url
declare multiple static servers, express would look for static resources from top to bottom and return the first matched ones
app.use(express.static('public1'))
app.use(express.static('public2'))
add url prefix to a static server, anyone who want to access resources under public have to add prefix ‘/user’
app.use('/user', express.static('public'))
Use nodemon to enable hot update
npm install nodemon -g
then use
nodemon app.js
to start the node application