Skip to main content

Express Js - එක්ස්ප්‍රස් js වලින් වැඩ ගනිමු


යළුවනේ, අද ම්ං මේ කියන්න යන්නේ තවත් JavaScript Library එකක් ගැන. ඒ Express JS. මේක Node.Js වලටම හදපු Web Framework එකක්. Express කියන්නේ වෙබ් සහ ජංගම යෙදීම් සඳහා ශක්තිමත් විශේෂාංගයක් සපයන අවම හා නම්‍යශීලී Node.js Web Framework එකක්. (වෙබ් යෙදුම් රාමුවක්).
මේ Framework එකෙන් පරිශීලක අතුරු මුහුනතයි (User Interface) එකයි Back End එකයි එකතු කරන්න API (Application Programming Interface) එකක් හදාගන්න පුළුවන්. ඒ කියන්නේ අපි හදන වෙබ් ඇප්ලිකේශන් (Web Application) එකේ පරිශීලකයාට පෙනෙන UI එකයි Server එකේ තියෙන ප්‍රධානම බිස්නස් ලොජික් (Business Logic) එකයි සම්බන්ධ කරන්න පුලුවන් මේ Framework එකෙන්.

Node JS : npm පාවිච්චි කරල හරිම පහසුවෙන් අපේ project එකට එකතු කරගන්න පුළුවන්. Project path එකේ console එකක් අරන් එකේ මේ code එක execute කරන්න මුළින්ම. මේකෙන් project එකට අවශ්‍ය Express node module එක ඔයාගේ project root එකේ node-modules එකට එකතු කරනවා.


$ npm install express --save

දැන් ඔයගේ ප්‍රොජෙක්ට් එකට Express dependencies එකතු වෙලා තියෙන්නේ. දැන් app එකක් හදන්න මෙන්න මේ විදිහට server.js කියල file එකක් open කරලා මෙ code එක ලියන්න. (මේ පියවර කරන්න කලින් Node Js ඔයාගේ computer/server එකෙ Install කරලා project එකටත් එකතු කරගෙන තියෙනවා කියලා හිතමු)


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}!`))


දැන් මේ කෝඩ් එක run කරන්න. const app = express() කොටසින් express app object එකක් ක්ෂණිකව හදාගන්න පුළුවන්. මේ app එක server එකක් ආරම්භ කරනවා. ඒ app එක අපි දීලා තියෙන ආකාරයට port 3000 එකට සම්බන්ධතාවයක් එන තුරු බලන් ඉන්නවා.

node server.js


දැන් web browser එකක් open කරලා http://localhost:3000 එකට යන්න. localhost කියන්නේ server එකේ නම. 3000 කියන්නේ server එකේ public open කරපු port එක. අවසානයේ web browser එකේ "Hello World!" කියල ඔබට දකින්න ලැබේවි. වරදක් ඇති නම් ප්‍රවේශමෙන් console එකේ ඇති errors කියවලා බලන්න.

Pro tip එකක්: ඔයා ඉන්නේ එකම network connection (Ex: wifi router) එකකට connect වෙලා නම් phone එකෙනුත් මේ app එක බලන්න පුලුවන්. කරන්න තියෙන්නේ localhost වෙනුවට ඔබේ පරිගණකයේ IP ලිපිනය යෙදීමයි. Ex: http://192.168.1.1:3000

මේ තාක්ෂණික කරුණු හොදින් මතක තියාගන්න. දිගටම node and express එක්ක practice කරන්න. තවත් කරුණු අත්දැකීමෙන්ම ඔබට අවබෝධ වේවි. express වලින් ලොකු ලොකු වැඩ කරන්න පුළුවන්. Routers, Controllers සහ Models ගැනත් තව ගොඩක් කරුණු තියෙනවා. අපි ඒ ගැන ඉදිරියේදී කතා කරමු.

Comments

Danny Danials said…
You will like it to enjoy our new app Score! Hero Mod Apk : which you could download and enjoy loose.

Popular posts from this blog

GitHub පාවිච්චි කරලා කරන්න පුළුවන් දේවල් මොනවද?

GitHub පාවිච්චි කරන ප්‍රධානම දේ තමයි Coding. තමන්ගේ Code එකක් පරෙස්සමට තියාගන්න හුගක් අය Github පාවිච්චි කරනවා. තව Documentation කරන්න තියෙන පහසුව. ඔබ දැකල තියෙනවනම් repository එකක් create කරද්දී අපිට README file එකත් හදාගන්න පුළුවන්. මේකේ මුළු project එකටම අදාලව files තියෙන විදිහ දක්වන්න README file එක පාවිච්චි කරනවා.  තවත් වැදගත් දෙයක් තමයි Issue Tracking කරන්න Github පාවිච්චි කරනවා. Commits History එක maintain කරන්න Github පාවිච්චි වෙනවා. Commits කියන්නේ මොනාද කියල ප්‍රශ්නයක් ආවනම් අපි ඒ ගැන ඉස්සරහට කතා කරමු. pulse, contributors, commits, code frequency, punch card, network, members වගේ ප්‍රධාන සාධක ගණනාවක් මේ Project එකකට බලපානවා. මේවා ගැන graphs ලබාගන්න පුළුවන්.  Email Notifications කෙනෙක්ව mention කිරීමේ හැකියාව Emojis එකතු කිරීම https://username.github.io  යන ආකාරයේ කුඩා websites host කිරීමේ හැකියාව Common Vulnerabilities  වලදී Security Alert එකක් ලැබීම  වගේ දේවල් මේකේ අන්තර්ගත වෙනවා. මේ තමයි Github web interface එක.  ...

Science Animated - Chemistry, Physics Experiments On Android Mobile

  " Science Animated " is an educational app that will allow you to conduct physics and chemistry experiments in an easy and really entertaining way within your classroom and beyond. With "Science Animated", you will be able to create engaging experiments utilizing the accelerator, the pH scale and other scientific instruments. You will also find pre-designed educational games that have been especially created for you! "Science Animated" is transforming physics and chemistry from theoretically intense to intensely fun!   ############## Features ############## * Earn more points while you learn. * Use your points to activate all premium content for free. * Share and redeem points. * Login with google to save your points and use across all Asia Cloud Apps. ################ Labs ############### * pH Scale * pH Scale: Basics * Arithmetic * Molecular shapes * Shapes of the molecules: basic points * Acid solvents * Light reflex * Oh's law * Resistance of wir...