Initial commit

This commit is contained in:
Doc-T-or
2024-01-18 14:06:11 +03:00
commit 9b74f35205
21 changed files with 32845 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = 5000;
app.use(cors());
app.use(bodyParser.json());
let notes = [];
app.get('/api/notes', (req, res) => {
res.json(notes);
});
app.post('/api/notes', (req, res) => {
const newNote = req.body.note;
if (newNote.trim() !== '') {
notes.push(newNote);
res.json({
success: true
});
} else {
res.json({
success: false,
error: 'Note cannot be empty'
});
}
});
app.delete('/api/notes/:index', (req, res) => {
const index = parseInt(req.params.index);
if (index >= 0 && index < notes.length) {
notes.splice(index, 1);
res.json({
success: true
});
} else {
res.json({
success: false,
error: 'Invalid index'
});
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
+1234
View File
File diff suppressed because it is too large Load Diff
+18
View File
@@ -0,0 +1,18 @@
{
"name": "notes-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.18.2"
}
}