Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ test
hotfix
refactor

*/
1) GET - READ DATA
2) POST - CREATE DATA
3) PUT - UPDATE DATA
4) DELETE - DELETE DATA
*/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./server.js"
},
"repository": {
"type": "git",
Expand Down
33 changes: 28 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,41 @@ const express = require('express');

const app = express();

const cars = [
'Audi',
'Volga',
'BMW',
];
// filter
// eslint-disable-next-line func-names
// const filter = function () {
// const tmp = {};
// // eslint-disable-next-line no-return-assign
// return cars.filter(a => (a in tmp ? 0 : tmp[a] = 1));
// };
// filter

app.get('/', (req, res) => {
res.send('<center>Hello world</center> ');
res.send(cars.join('<br>'));
});

// больше не хуйни
app.get('/hello/:name', (req, res) => {
app.get('/cars/add/:name', (req, res) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Коротко и лаконично:

app.get('/cars/add/:name', (req, res) => {
const {
name,
} = req.params;

if (cars.indexOf(name) >= 0) {
res.send('Already exists');
} else {
cars.push(name);
res.send(${name} added);
}

});

const {
name,
} = req.params;
res.send(`<center>Hello ${name}</center> `);

function filters(cars, name) {
for (let i = 0; i < cars.length; ++i) {
if (cars[i] === name) {
return res.send('Already have');
}
}
res.send(`ok ${name} add`);
return cars.push(name);
}
filters(cars, name);
});

app.listen(3005 || undefined, () => {
console.log('Server started');
console.log('Server started!!!');
});