Node.JS למתחילים
קוד לשרת Node.JS ראשון שכתבנו:
var http = require('http'); var utils = require('./utils.js'); var server = http.createServer(function(req,res) { res.writeHead(200,{"Content-Type" : "text/html"}); res.write(`<html><body>${utils.getGreet('Avi')}</body></html>`); res.end(); }); server.listen(3000); console.log("Server is running...");
קוד לשרת Express ראשון שכתבנו:
const express = require('express'); const app = express(); app.get('/getForm',function(req,resp) { resp.sendFile(__dirname + "/appForm.html"); }); app.get('/getData',function(req,resp) { console.log(req.query.fname); console.log(req.query.lname); resp.send("Data recieved"); }); app.listen(3000);
כל שאר הדוגמאות זמינות אונליין בגיטהאב בקישור:
https://github.com/tocodeil/nodejs-webinar-examples