Tutorial

Modernisasi aplikasi Node.js

Pelajari cara menggunakan IBM Bob untuk modernisasi aplikasi dengan mengupgrade Node.js Express API dari versi 16 ke 22. Coba AI-assisted development dengan modes, approvals, dan literate coding dalam tutorial hands-on ini.

Pengenalan

Bob adalah AI SDLC partner yang melengkapi workflow yang sudah ada. Dalam tutorial ini, kamu mempelajari beberapa fitur inti Bob dengan memodernisasi TypeScript Express API dari Node.js 16 ke Node.js 22. Kamu tidak perlu pengalaman di Node.js atau TypeScript untuk menyelesaikan tutorial ini.

Fitur utama yang akan kamu pelajari

  • Modes: Persona khusus yang menyesuaikan perilaku Bob untuk task tertentu.
  • Context mentions: Referensikan elemen proyek tertentu dalam percakapan dengan Bob.
  • Approval workflow: Tinjau setiap tool yang direncanakan Bob sebelum dieksekusi.
  • Literate coding: Tulis kode dengan Bob langsung di editormu.

Prasyarat

Setup workspace-mu

Launch IBM Bob

Launch aplikasi IBM Bob.

Clone repository tutorial

Clone repository yang berisi aplikasi contoh dengan mengklik ikon files di panel Bob IDE. Kemudian klik Clone Repository, dan tempel repository GitHub berikut ke search bar:

https://github.com/IBM/bob-demo.git

Nonaktifkan auto-approval

Pastikan auto-approval dimatikan di Permissions.

Bangun lingkungan yang di-containerize

Beralih ke Agent mode

Beralih Bob ke Agent mode.

Buat Dockerfile

Masukkan prompt di antarmuka chat Bob:

Create a Dockerfile for this Node.js TypeScript application. 
It should use Node 16 to match the current application version, build the TypeScript code, and run the app on port `3000`.

Klik Approve untuk mengizinkan Bob membaca file, kemudian klik Save untuk membuat file.

Verifikasi aplikasi legacy

Build and test the legacy application using Docker to verify it works correctly before modernization. The application should respond to API requests at /api/todos with sample data.

After testing, clean up the container.

Jelajahi codebase Node.js dengan Ask mode Bob

Beralih ke Ask mode Bob. Ask mode hanya bisa membaca file, sehingga kamu bisa menjelajahi kode dengan aman tanpa membuat perubahan.

Gunakan @ context mentions untuk meninjau proyek

@package.json What Node.js version is this project using? What dependencies would need updating for Node.js 22? Give me a short summary.
@tsconfig.json What module system and compiler settings is this TypeScript project using? What dependencies would need updating for Node.js 22? Give me a short summary.
@Dockerfile What Node.js version does this Dockerfile use? What would need to change for Node.js 22? Give me a short summary.

Modernisasi API dengan Agent mode Bob

Beralih kembali ke Agent mode dan jalankan prompt modernisasi berikut:

@package.json @tsconfig.json @Dockerfile

Modernize this Express API from Node.js 16 to Node.js 22. Keep the API functionality identical - this is a platform upgrade, not a feature change. Give me a short summary.

Tandai modernisasi selesai

Gunakan fitur literate coding Bob untuk memperbarui judul todo contoh.

Aktifkan mode literate coding

Navigasi ke folder express-todo-api dan klik src/db.ts. Toggle mode literate coding dengan mengklik ikon magic wand di toolbar editor.

Tulis instruksimu

Di file src/db.ts, tempel instruksi berikut di bagian atas file:

// Find the sample todo object's title property and change it to "Welcome to the Modernized Node.js 22 API"

Hasilkan kode

Klik Generate.

Terima perubahan

Klik Accept all untuk menerapkan perubahan.

Verifikasi aplikasi yang dimodernisasi dengan Docker

Verify the modernized Node.js 22 application works by building and testing it with Docker. Check that the API responds at /api/todos and shows the updated todo title. Clean up when done. Give me a short summary. I also want to see the validation of the new title.

Langkah selanjutnya

Bagaimana topik ini?