GDSC NYUST
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: VS Code & Node.js課程 date: 2023-10-18 langs: zh type: slide --- ### GDSC NYUST x 資訊創客社 <br> ### 軟體開發工具入門讀書會 #### VS Code & Node.js課程 <br> #### 2023/10/18 ( Wed ) 19:00 - 21:00 #### 講師:蘇祐民 #### 本次課程影片: <img src="" height="200px"> --- # VSCode & Node.js *YoMin Su* --- ## 課程簡報 ---- ![](https://hackmd.io/_uploads/S1qoDxTZp.png) > URL: https://reurl.cc/jv9pXm --- ## 課程簡介 ---- ### 簡單的說 - 在上週的環境中開始進行JavaScript開發 - 透過VSCode對設計好的程式碼進行除錯 - 初探Node.js專案 ---- ### 今日目標 1. 安裝VSCode 2. 在VSCode中安裝 WSL/SSH 套件 3. 透過VSCode連線到目標機器 4. 在 WSL/VM 中安裝 Node.js 5. 介紹活動列中的各大項功能 6. 在VSCode中安裝 JS/TS 套件 7. 介紹Node.js 8. 透過VSCode對Node.js應用程式進行除錯 9. 介紹Node.js專案與套件管理工具 10. 重點回顧與學習資源分享 --- ## 環境準備 ---- ### 安裝VSCode 總有人電腦中沒有,所以跟著來操作: Windows ```shell= winget install Microsoft.VisualStudioCode -i ``` <br/> macOS ```shell= brew install --cask visual-studio-code ``` > mac的同學若沒有brew,請[點我](https://code.visualstudio.com/docs/?dv=osx) ---- ### 在Linux環境中安裝Node.js 首先要進入到環境中,所以... ```shell= wsl bash ``` 在你的終端機中輸入上述任一項就可以了喔! ![](https://hackmd.io/_uploads/BkMTV-pba.png) ---- ### 安裝Node.js(2) 先回到家目錄: ```bash= cd ~ ``` 接著利用 Node.js 的Repo來安裝: ```bash= sudo apt-get update sudo apt-get install -y ca-certificates curl gnupg sudo mkdir -p /etc/apt/keyrings curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg ``` > 上面的指令用於新增Repo的金鑰,為的是讓系統信任套件的簽名! ---- ### 安裝Node.js(3) 新增套件來源 (NODE_MAJOR 對應要的安裝版本) ```bash= NODE_MAJOR=20 echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list ``` 安裝開始: ```bash= sudo apt update && sudo apt install nodejs -y ``` ---- ### 驗證Node.js安裝 請輸入: ```bash= node -v ``` 會像下圖這個樣子(版本根據前面MAJOR而定) ![](https://hackmd.io/_uploads/S1OKSf6-p.png) ---- ### 啟用Corepack Corepack 是 Node.js 中用於管理『包管理器』的管理器 (Package Manager Manger) <br/> 啟用後就可以直接開始使用 ```bash= sudo corepack enable ``` ---- ### 驗證Corepack 啟用之前: ![](https://hackmd.io/_uploads/ByQWwf6bp.png) 啟用之後: ![](https://hackmd.io/_uploads/HynmwzT-T.png) --- ## VSCode 導覽 ---- ### 操作介面 ![](https://hackmd.io/_uploads/H1J5PzTZp.png) ---- ### 活動列 | | 名稱 | 用途 | | --------------------------------------------------- | ---------- | ------------------------ | | ![](https://hackmd.io/_uploads/S1U-OMT-a.png =50x) | 檔案總管 | 在專案中的各檔案來回游走 | | ![](https://hackmd.io/_uploads/BJuz_fTbT.png =50x) | 搜尋 | 在專案中進行全域搜尋 | | ![](https://hackmd.io/_uploads/r1UXOz6b6.png =50x) | 原始檔控制 | Git版本控管的圖形介面 | | ![](https://hackmd.io/_uploads/HJgEV_faWp.png =50x) | 執行與偵錯 | 除錯工具的部分 | | ![](https://hackmd.io/_uploads/S1gSdGaWT.png =50x) | 延伸模組 | 缺套件找這裡 | ---- ### 狀態列 ![](https://hackmd.io/_uploads/ryj89GaWa.png) ---- ### 狀態列左側:全域項目 ![](https://hackmd.io/_uploads/ryYH3zp-p.png) | 功能 | 描述 | | ------------ | ------------------------ | | 開啟遠端視窗 | 用於連接遠端目標 | | 版本控制 | 顯示目前分支與同步狀態 | | 問題偵測 | 用於顯示專案中是否有錯誤 | | 連接埠 | 用於顯示轉接的連接埠 | ---- ### 狀態列右側:上下文項目 ![](https://hackmd.io/_uploads/S1DD2faZa.png) | 功能 | 描述 | | ------------ | ------------------------ | | 行 / 欄 | 顯示光標當下在哪裡 | | 選擇縮排 | 顯示每次按下Tab的結果 | | 選取編碼 | 設定目前檔案的編碼格式 | | 選取行尾順序 | 設定檔案的換行規則 | | 選取語言模式 | 設定檔案的程式語言 | ---- ### 開啟專案 點選活動列的『檔案總管』,再按下『開啟資料夾』 ![](https://hackmd.io/_uploads/BknjaGpWp.png =400x) ---- ### 檢視專案資訊 ![](https://hackmd.io/_uploads/rkRmZ7aWp.png) ---- ### 版本控管資訊 ![](https://hackmd.io/_uploads/By6wWQTZa.png =500x) ---- ### 執行與偵錯 ![](https://hackmd.io/_uploads/rkS2W76bp.png) --- ## Node.js 教學時間 ---- ### 變數宣告 ![](https://hackmd.io/_uploads/B184zmab6.png) ```javascript= let // 區域變數 var // 全域變數 const // 常數 ``` ---- ### 資訊輸出 ![](https://hackmd.io/_uploads/Syi1m7p-T.png) ```javascript= console.log("放什麼都行"); ``` ---- ### 資訊輸入 ![](https://hackmd.io/_uploads/B18MV76b6.png) ```javascript= const stdin = process.openStdin(); //建立stdin物件 //加入事件監聽器,當輸入後,顯示輸入的資訊 stdin.addListener("data", (d) => { console.log(d.toString().trim()); }); ``` ---- ### 宣告方法 ![](https://hackmd.io/_uploads/S1GeHXabp.png =400x) ```javascript= function abc() { //標準宣告 console.log("xyz"); } let def = () => { //簡短宣告 console.log("ijk"); } ``` ---- ### JS物件 ![](https://hackmd.io/_uploads/SkZ3BQTWp.png =500x) 執行結果: ![](https://hackmd.io/_uploads/HyNTHQpZp.png =500x) ---- ### JS陣列 ![](https://hackmd.io/_uploads/S1hcLQT-a.png =500x) 執行結果: ![](https://hackmd.io/_uploads/BJAsL76ZT.png =500x) ---- ### Node.js 提供的資訊 印出來: ```javascript= console.log(process); ``` 直接看: ![](https://hackmd.io/_uploads/r1x68DQaZa.png =500x) ---- ### 來寫點東西試試 ```javascript= let student1 = { name: "John", age: 8 } let student2 = { name: "Cindy", age: 9 } let student3 = { name: "Jeff", age: 8 } let students = [] students.push(student1, student2, student3); let ages = students.map((s) => s.age); let total = 0; ages.forEach(a => { total += a; }); console.log(total); ``` --- ## JS 偵錯 ---- ### 中斷點 ![](https://hackmd.io/_uploads/By-MAQpZT.png =500x) 在行左側點一下,讓紅色點點出現 ---- ### 逐步執行 ![](https://hackmd.io/_uploads/rk1CC7Tbp.png =300x) | | 說明 | | ---------- | ------------------ | | 繼續 | 跳至下一個中斷點 | | 不進入函式 | 跳至下一個命令 | | 逐步執行 | 一條一條跑 | | 跳離函式 | 跳過函式內執行細節 | | 重新啟動 | 就是重新開始 | | 停止 | 結束偵錯 | --- ## JS 專案 ---- ### 初始化專案 ```bash= yarn init -2 ``` 執行後的資料夾: ![](https://hackmd.io/_uploads/S1UUg4pWp.png) ---- ### 專案定義檔 > package.json ```json= { "name": "Temp", "packageManager": "yarn@3.6.4" } ``` ---- ### 新增套件 ```bash= yarn add express ``` 完成後的package.json ```json= { "name": "Temp", "packageManager": "yarn@3.6.4", "dependencies": { "express": "^4.18.2" } } ``` ---- ### 如果是開發依賴 ```bash= yarn add -D @types/express ``` 完成後的package.json ```json= { "name": "Temp", "packageManager": "yarn@3.6.4", "dependencies": { "express": "^4.18.2" }, "devDependencies": { "@types/express": "^4.17.20" } } ``` ---- ### 加上自定義指令 假設想要執行檔案: ```json= "scripts": { "dev": "node src/index.js" } ``` 將上述加入到package.json中 ![](https://hackmd.io/_uploads/BkHjG4aZ6.png =500x) --- ## 學習資源 ---- - [MDN Web Docs](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript) - [Microsoft Learn 偵錯](https://learn.microsoft.com/zh-tw/training/modules/debug-nodejs/) - [Introduction | Yarn](https://yarnpkg.com/getting-started) --- ## Q & A 有什麼疑惑的嗎? --- ## 下一次課程 > Git & GitHub 分支控制、合併分支、Pull Request... --- ## Bye Bye (❁´◡\`❁)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully