第一天,我沒有先畫產品架構圖或是想一堆功能清單,而是先確認Hello World 等級的Sever能不能動起來,因為30天的專案,基礎跟記錄機制如果沒打穩,後面很容易亂掉。
第一部分
安裝好Node.js後,寫了第一隻最陽春的伺服器程式:
const http = require('http');
const sever = http.creatSever((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'test/plain');
res.end('Hello, Todo App!');
});
sever.listen(3000, () => {
console.log('伺服器啟動於 http://localhost:3000');
});
執行node sever.js後,打開瀏覽器輸入 http://localhost:3000 ,畫面順利顯示出Hello, Todo App!。
第二部分
確定Server能動之後,接著把整個資料夾接上github版本控制:
git init
git add .
git commit -m "Day 1 : 建立基本 HTTP Server"
git branch -M main
git remote add origin https://github.com/yyyehh/todo-app.git
git push -u origin main
執行完之後,終端機顯示[new branch] main → main,回到github網站重新整理,server.js也順利出現在我的repository裡面。
今日心得/遇到的問題
這是我第一次學習如何使用node.js,並在沒有老師的指導下透過claude的協助之下完成程式碼,且上傳至github,第一天的內容很基礎,甚至只有建立一個基本的東西,不過對於後續程式碼的撰寫及上傳有更進一步的了解。還有在安裝Node.js的時候,一度因為執行原則被擋下npm指令,在詢問AI之後,利用Set-ExecutionPolicy調整後就解決了這個問題。
專案網址:https://github.com/yyyehh/todo-app.git