我正在学习节点和Express,我想在Express Example中重复一个单词
用户访问...... / repeat / hello / 5我希望“ hello”在浏览器页面上打印5次,
如果他们这样做/ repeat / hello / 3,我希望“ hello”打印3次。我怎样才能做到这一点?如果可以的话,我可以使用for循环嵌套吗?
这是我的代码
var express = require("express");
var app = express();
//const repeating = require("repeating");
app.get("/", function(req,res){
res.send("Hi there, welcome to my Assignment!");
});
//pig
app.get("/speak/pig", function(req,res){
res.send("The pig says Oink");
});
//cow
app.get("/speak/cow", function(req,res){
res.send("The cow says Moo");
});
//dog
app.get("/speak/dog", function(req,res){
res.send("The dog says Woof, Woof!");
});
app.get("/repeat/hello/:3", function(req,res
res.send("hello, hello, hello");
});
app.get("/repeat/blah/:2", function(req,res){
res.send("blah, blah");
});
app.get("*", function(req,res){
res.send("Sorry, page not …Run Code Online (Sandbox Code Playgroud)