coding with ☕️
2 subscribers
262 photos
14 videos
11 files
165 links
Anwendungsentwicklung
Download Telegram
2. Validatsiya, Paginatsiya, Searching – 0/12 | 444 min
Bu katta va muhim bo‘lim.

Validatsiya – foydalanuvchi noto‘g‘ri data yuborishini to‘xtatish.

Masalan: parol 6 belgidan kam bo‘lmasin, email noto‘g‘ri formatda bo‘lmasin va h.k.

joi, express-validator modullari bilan ishlatiladi.

📄 Paginatsiya (sahifalash) – katta ma’lumotni sahifalab yuborish.

Masalan: 1000 ta kitobni bir vaqtning o‘zida yuborish emas, balki page=1&limit=10 orqali faqat 10 tasini yuborish.

Bu foydalanuvchi uchun ham, server uchun ham qulay.

🔍 Searching – ma’lumotlar ichidan qidirish.

Masalan: ?q=java bo‘lsa, kitoblar orasidan nomida “java” borlarini topish.
Masalan: books (kitoblar) haqida CRUD (Create, Read, Update, Delete) API yarating.
Route — bu URL manzili orqali serverga yuboriladigan so‘rov (request) manzilidir. Har bir route biror bir amalgacha yo‘l ko‘rsatadi.
CRUD
| Tushuncha | Nima?                        | Misol                                  |
| --------- | ---------------------------- | -------------------------------------- |
| Route | URL orqali serverga murojaat | `/todos`, `/users/:id` |
| CRUD | Ma’lumotlar bilan amallar | Yaratish, O‘qish, Yangilash, O‘chirish |
MongoDB bilan: mongoose orqali ulanadi
const express = require('express')
const app = express()

// respond with "hello world" when a GET request is made to the homepage
app.get('/', (req, res) => {
res.send('hello world')
})
const express = require("express");
const app = express();

app.get("/", function(req, res) {
res.send("This is a get request!!\n");
});
app.post("/", function(req, res) {
res.send("This is a post request!!\n");
});

app.put("/", function(req, res) {
res.send("This is a put request!!\n");
});

app.get("/hey", function(req, res) {
res.send("This is a get request to '/hey'!!\n");
});

app.listen(3000);
const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
res.send('Hello World!')
})

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
coding with ☕️ pinned «const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.listen(port, () => { console.log(`Example app listening on port ${port}`) })»
express -h

Usage: express [options] [dir]

Options:

-h, --help output usage information
--version output the version number
-e, --ejs add ejs engine support
--hbs add handlebars engine support
--pug add pug engine support
-H, --hogan add hogan.js engine support
--no-view generate without view engine
-v, --view <engine> add view <engine> support (ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)
-c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
--git add .gitignore
-f, --force force on non-empty directory
express --view=pug myapp

create : myapp
create : myapp/package.json
create : myapp/app.js
create : myapp/public
create : myapp/public/javascripts
create : myapp/public/images
create : myapp/routes
create : myapp/routes/index.js
create : myapp/routes/users.js
create : myapp/public/stylesheets
create : myapp/public/stylesheets/style.css
create : myapp/views
create : myapp/views/index.pug
create : myapp/views/layout.pug
create : myapp/views/error.pug
create : myapp/bin
create : myapp/bin/www
app.get('/', (req, res) => {
res.send('Hello World!')
})