Zack Saadioui
8/27/2024
1
curl -fsSL https://ollama.com/install.sh | sh
1
ollama pull phi3
1
ollama run phi3
1
mkdir todo-app && cd todo-app
1
npm init -y
1
npm install express cors nodemon body-parser
1
server.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
const express = require('express'); const cors = require('cors'); const bodyParser = require('body-parser'); const app = express(); const PORT = process.env.PORT || 5000; app.use(cors()); app.use(bodyParser.json()); let tasks = []; app.get('/tasks', (req, res) => { res.json(tasks); }); app.post('/tasks', (req, res) => { const task = req.body; tasks.push(task); res.status(201).send(task); }); app.delete('/tasks/:id', (req, res) => { tasks = tasks.filter((_, index) => index !== parseInt(req.params.id, 10)); res.sendStatus(204); }); app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });
1 2
npx create-react-app client cd client
1
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
import React, { useState, useEffect } from 'react'; import './App.css'; function App() { const [tasks, setTasks] = useState([]); const [taskInput, setTaskInput] = useState(''); useEffect(() => { fetch('http://localhost:5000/tasks') .then(res => res.json()) .then(data => setTasks(data)); }, []); const addTask = async (task) => { await fetch('http://localhost:5000/tasks', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ task }) }); setTasks([...tasks, { task }]); setTaskInput(''); }; const removeTask = async (id) => { await fetch(`http://localhost:5000/tasks/${id}`, { method: 'DELETE' }); setTasks(tasks.filter((_, index) => index !== id)); }; return ( <div className="App"> <h1>To-Do List</h1> <input value={taskInput} onChange={e => setTaskInput(e.target.value)} placeholder="Add your task here..." /> <button onClick={() => addTask(taskInput)}>Add Task</button> <ul> {tasks.map((task, index) => ( <li key={index}> {task.task} <button onClick={() => removeTask(index)}>✅</button> </li> ))} </ul> </div> ); } export default App;
1 2
npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p
1 2 3 4 5 6 7
module.exports = { content: ["./src/**/*.{js,jsx,ts,tsx}",], theme: { extend: {}, }, plugins: [], };
1 2 3
@tailwind base; @tailwind components; @tailwind utilities;
1
2
bash
node server.js
1
2
3
bash
cd client
npm start
Copyright © Arsturn 2024