اول از همه Nodejs رواز سایتش میگیریم دانلود و نصب میکنیم .
با node -v توی cmd میتونیم ورژن برنامه رو متوجه بشیم .
یه فایل js میسازیم مثلا firstNode.js و توی اون کد زیر رو مینویسیم
var http = require("http") let ourApp = http.createServer(function(req , res){ if(req.url == "/about"){ res.end("welcome to my company !") } else{ res.end("welcome to website !") } }) ourApp.listen(3050)
استفاده از expressjs
برای نصب npm install express زده میشه
var express = require("express") let ourApp = express(); ourApp.use(express.urlencoded({ extended: false })) ourApp.get('/', function (req, res) { res.send(` <form action="answer" method="POST"> <h3>What is your answer?</h3> <input type="text" name="myTxt" > <button> Submit Date </button> </form> `) }) ourApp.post('/answer', function (req, res) { if (req.body.myTxt == "yes") { res.send('<p> you are yes man ! </p>') } else { res.send('why yo are always no ! ') } }) ourApp.listen(3050)
npm install nodemon
npm init -y
"scripts": { "watch" : "nodemon YourAppName" , }
npm run watch
تا کنون نظری داده نشده است .
اولین کسی باشید که دیدگاه خود را ثبت می کند .
لطفا منتظر بمانید...