INFO 30005
Web Information Technologies
Introduction to
Express.js
Copyright By PowCoder代写 加微信 powcoder
Express = simpler code
compare our Node-only code from last lecture …
This lecture
I suggest an approach for designing your app code:
1. Decide which routes your app needs
2. Code ‘stubs’ for each route
3. Code small HTML pages to test the design
4. Static HTML files instead of writing HTML from Express
5. Convert static files to Handlebars templates
6. Insert data into hbs templates – at first, hard-coded JSON
7. Now, fetch the data from MongoDB database
8. add a header and footer and some CSS to main.hbs (topics 5-8 are covered in more detail later in the semester)
Install Express
npm init -y
2 package.json appears
npm install
Let’s write an Express server for Food Buddy
What routes do we need to display these screens?
/filter (GET and POST)
list out the routes (write simple stubs)
HTML and Post
static HTML files
install express-handlebars
Handlebars templates
Handlebars templates with data (hard-coded JSON)
install MongoDB and set up collection
Handlebars templates, with data from MongoDB
add header/footer and some CSS to main.hbs
Organising your code
package.json public/ node_modules/ app.js
models/ views/ controllers/ routes/ middleware/
(we’ll cover this in more detail as we proceed through the semester)
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com