Files
stupid-apis/src/routes/api/string/countWords.js
T
johannesbot 19c477aa05
Build and Deploy / build (push) Successful in 1m44s
Build Release / build (push) Successful in 58s
Build and Deploy / deploy (push) Successful in 26s
12 new API endpoints
2026-06-16 20:51:18 +02:00

18 lines
412 B
JavaScript

const express = require('express');
const router = express.Router();
function countWords(str) {
return String(str).trim().split(/\s+/).filter(w => w.length > 0).length;
}
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: countWords(input) });
});
router.get('/:string', (req, res) => {
res.json({ ret: countWords(req.params.string) });
});
module.exports = router;