Express babban tsarin aikace-aikacen gidan yanar gizo ne mai ƙarfi da sassauƙa bisa Node.js. Tare da tsarin sa mai sauƙi da sauƙi mai nauyi, Express yana ba ku damar gina aikace-aikacen yanar gizo masu amsa mai amfani da sauri.
Express yana ba da fasali da kayan aikin da suka wajaba don sarrafa buƙatun HTTP, hanyoyin gini, sarrafa kayan tsakiya, da samar da abun ciki mai ƙarfi. Yana ba ku damar ƙirƙirar aikace-aikacen gidan yanar gizo masu ƙarfi da sassauƙa, daga gidajen yanar gizo masu sauƙi zuwa hadaddun aikace-aikacen yanar gizo
Don amfani Express, kuna buƙatar shigar da tsarin kuma ƙirƙirar sabar don sauraron buƙatun abokan ciniki. Ta hanyar ayyana hanyoyi da tsaka-tsaki, zaku iya sarrafa buƙatun, samun damar bayanai, aiwatar da ingantaccen aiki da tsaro, da nuna abubuwan ciki mai ƙarfi ga masu amfani.
Ga takamaiman misali na gina aikace-aikacen lissafin abin yi ta amfani da Express:
Mataki 1: Shigarwa da Saitin Ayyuka
- Sanya Node.js akan kwamfutarka( https://nodejs.org ).
- Bude Terminal kuma ƙirƙirar sabon jagora don aikinku:
mkdir todo-app
. - Matsa zuwa cikin kundin aikin:
cd todo-app
. - Fara sabon aikin Node.js:
npm init -y
.
Mataki 2: Shigar Express
- Shigar da Express kunshin:.
npm install express
Mataki 3: Ƙirƙiri fayil ɗin server.js
- Ƙirƙiri sabon fayil mai suna server.js a cikin kundin aikin.
- Bude fayil ɗin uwar garken.js kuma ƙara abun ciki mai zuwa:
// Import the Express module
const express = require('express');
// Create an Express app
const app = express();
// Define a route for the home page
app.get('/',(req, res) => {
res.send('Welcome to the To-Do List App!');
});
// Start the server
app.listen(3000,() => {
console.log('Server is running on port 3000');
});
Mataki 4: Guda Application
- Bude Terminal kuma kewaya zuwa kundin aikin(todo-app).
- Gudanar da aikace-aikacen tare da umarni:
node server.js
. - Bude burauzar gidan yanar gizon ku kuma sami damar URL:
http://localhost:3000
. - Za ku ga saƙon "Barka da zuwa Lissafin Abubuwan Yi!" nuna a cikin browser.
Wannan misali ne mai sauƙi na gina aikace-aikacen yanar gizo ta amfani da Node.js da Express. Kuna iya faɗaɗa kan wannan aikace-aikacen ta ƙara fasali kamar ƙarawa, gyarawa, da share ayyuka daga jerin abubuwan yi.