app variable is defined by
const app = express();
This code is working fine:
app.get('/posts/:id', (req, res) => {
res.json( post_creator.CreatePost(req.params.id) );
});
But the below code is not working:
const post_url_with_id = '/posts/:id';
app.get(post_url_with_id, (req, res) => {
res.json( post_creator.CreatePost(req.params.id) );
});
How can i create function with parameter can pass express.get or post methods?
I want to implement like next function
function serve_post( post_url_with_id ) {
app.get(post_url_with_id, (req, res) => {
res.json( post_creator.CreatePost(req.params.id) );
});
}
Thanks for contributors.