Express and Node.js Training from StrongLoop

This document might be outdated relative to the documentation in English. For the latest updates, please refer to the documentation in English.

Hello world

Bu yerda Express dasturga eng sodda misol keltirilgan.


var express = require('express');
var app = express();

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

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});

req (request) va res (response) Node taqdim etayotgan obyektlar hisoblanadi, shuning uchun req.pipe(), req.on('data', callback) Express talab qilmaydigan boshqa obyektlar.

Dastur serverni ishga tushuradi va 3000 portdagi aloqani eshitib turadi. Javob sifatida bosh sahifaga “Hello World!” so’zi jo’natiladi. Qolgan barcha sahifalarga esa 404 Not Found javobi jo’natiladi.

Kodni yozib, app.js faylida saqlab qoying. Uni ishga tushurish uchun quyidagi buyruqni ishga tushiring:


$ node app.js

Natijani ko’rish uchun, brauzerdan http://localhost:3000/ manziliga kiring.