Static Files
/app.js
app.js
const express = require('express') const app = express() const port = 3000 const userRoute = require('./routes').user; app.set('view engine', 'pug') app.set('views', './views'); // https://expressjs.com/en/4x/api.html#req.body app.use(express.json()) // for parsing application/json app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded app.use(express.static('public')); // GET method route app.get('/', function (req, res) { res.render('index', { title: 'Hey', message: "ExpressJS" }) }) app.use('/users', userRoute); app.listen(port, () => console.log(`Example app listening on port ${port}!`))
/public/css/custom.css
2018
a { color: red; }
/views/index.js
index.js
extends ./layouts/common.pug block content div(class="container col-3") h3(class="text-uppercase text-center alert alert-danger mt-3")= message a(href='/users') Users br img(src="/images/bitcoin.png", width="200")
Command: npm start
<< back | next >>
0 nhận xét:
Post a Comment