Skip to content

Commit 09865cc

Browse files
committed
Add express samples
1 parent 03c4ac6 commit 09865cc

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

express/apppathparams.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
const express = require("express");
3+
const app = express();
4+
5+
app.get("/show/:name/:age/", (req, res) => {
6+
res.set({ "Content-Type": "text/plain; charset=utf-8" });
7+
let name = req.params.name;
8+
let age = req.params.age;
9+
let msg = `${name} is ${age} years old`;
10+
res.send(msg);
11+
});
12+
13+
app.listen(3000, () => console.log("Application started on port 3000"));

express/apppatternmatch.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env node
2+
const express = require("express");
3+
const app = express();
4+
5+
app.get("/city/:id([0-9]{1,5})", (req, res) => {
6+
res.set({ "Content-Type": "text/plain; charset=utf-8" });
7+
res.send(`id: ${req.params.id}`);
8+
});
9+
10+
app.listen(3000, () => {
11+
console.log("Application started on port 3000");
12+
});

express/appquery.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
const express = require("express");
3+
4+
const app = express();
5+
6+
app.get("/greet", (req, res) => {
7+
res.set({ "Content-Type": "text/plain; charset=utf-8" });
8+
let name = req.query.name;
9+
let msg = `Hello, ${name}`;
10+
res.send(msg);
11+
});
12+
13+
app.listen(3000, () => console.log("Application started on port 3000"));

express/appreqip.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env node
2+
const express = require("express");
3+
const app = express();
4+
5+
app.get("/", (req, res) => {
6+
res.set({ "Content-Type": "text/plain; charset=utf-8" });
7+
res.send(`The request IP is: ${req.ip}`);
8+
});
9+
10+
app.listen(3000, () => {
11+
console.log("Application started on port 3000");
12+
});

express/appsimple.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
const express = require("express");
3+
const app = express();
4+
app.get("/", (req, res) => res.send("Hello, there!"));
5+
app.listen(3000, () => console.log("Application started on port 3000"));

0 commit comments

Comments
 (0)