-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpress-route.js
More file actions
42 lines (34 loc) · 1.19 KB
/
express-route.js
File metadata and controls
42 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var express = require('express');
var http = require('http');
var app = express();
app.get ('/', function(request, response) {
response.end("Welcome to the my home page");
});
app.get ('/about', function(request, response) {
response.end("Welcome to the about page");
});
app.get ('/weather', function(request, response) {
response.end("It's sunny");
});
app.get ('/hello/:who/:city/:country', function(request, response) {
response.end("Hello, " + request.params.who + " from " + request.params.city +", " + request.params.country);
});
app.get ('/products/:type/:id', function(request, response) {
if (request.params.type ==1) {
response.send("<h1>Dresses category<h1> Product Id :" + request.params.id);
}
else if (request.params.type ==2) {
response.send("<h1>Guitar category<h1> Product Id :" + request.params.id);
}
else if (request.params.type ==3) {
response.send("<h1>Furniture category<h1> Product Id :" + request.params.id);
}
else {
response.send("<h1>Default Category<h1>");
}
});
app.use (function(request, response) {
response.statusCode = 404
response.end("404 error");
});
http.createServer(app).listen(5000);