Skip to content

Instantly share code, notes, and snippets.

@AlexSKuznetsov
Created June 16, 2020 19:17
Show Gist options
  • Select an option

  • Save AlexSKuznetsov/486d2ec696e98c5c85e4ab85d791f6f7 to your computer and use it in GitHub Desktop.

Select an option

Save AlexSKuznetsov/486d2ec696e98c5c85e4ab85d791f6f7 to your computer and use it in GitHub Desktop.
// ------ БАЗА ----- //
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(process.env.PORT || 3000)
/// --------СТАТИКА ------ ///
// подключение статической директории
app.use(express.static('public'))
// для создания виртуальной статической директории
app.use('/static', express.static('public'))
// или
app.use('/static', express.static(path.join(__dirname, 'public')))
/// ----- ПОДКЛЮЧЕНИЕ HBS ----- ////
app.set('view engine', 'hbs')
/// ---- РОУТИНГ ---- //// app.METHOD(PATH, HANDLER)
// пример гет запроса
app.get('/', function (req, res) {
res.send('hello world')
})
// обработка параметров в запросе
// Route path: /users/:userId/books/:bookId
// Request URL: http://localhost:3000/users/34/books/8989
// req.params: { "userId": "34", "bookId": "8989" }
app.get('/users/:userId/books/:bookId', function (req, res) {
res.send(req.params)
})
// подключение роутера в отдельном файле
const route = express.Router()
// какой то метод
module.exports = route;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment