-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (41 loc) · 967 Bytes
/
app.js
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
43
44
45
46
47
48
49
/*const express = require('express')
const app = express()
const PORT = process.env.PORT || 3000
function string_square(s){
if (typeof(s)==String){
res = length(s)*length(s);
} else {
res = -1;
}
return res;
}
app.get('/square', (req, res) => {
const s = req.query.string
res = string_square(s);
res.status(200).json({
result: res
})
})
app.listen(PORT, () => console.log('Example app listening on port'+ PORT))*/
const express = require('express');
const app = express();
const port = process.env.PORT || 3000
function string_square(s) {
if (typeof s === 'string'){
var res = (s.length)*(s.length);
} else {
var res = -1;
}
return res;
}
app.get('/', (req,res) => {
res.json({
message: 'tua madre'
});
});
app.get('/square', (req, res) => {
res.status(200).json({
result: string_square(req.query.string)
});
});
app.listen(port);