Skip to content

Home

Deploying a Koa.js Application to an AWS EC2 Ubuntu Instance

I am developing an application using Koa.js, a new web framework created by the team behind Express. In this step-by-step tutorial, I'll guide you through deploying a Koa.js application on an Amazon Web Services (AWS) Ubuntu server.

Launching the Ubuntu Instance on AWS

First, launch an Ubuntu instance on AWS. You'll need to modify the security group settings.

If you don't make these changes, attempting to access the public domain in a browser will result in a "Connecting" state until it times out, rendering the site unreachable.

By default, the launch wizard only enables SSH.

SSH Only

Click the "Edit" button to add inbound rules for HTTP port 80 and HTTPS port 443.

Edit Inbound Rules

Installing Node.js

SSH into your instance and install Node.js according to the official documentation:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Setting Up Nginx as a Reverse Proxy Server

Next, install Nginx:

sudo apt-get update
sudo apt-get install nginx

Open the configuration file and make the following edits. Don't forget the semicolons:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/yourApp;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Save the file and restart the Nginx service:

sudo systemctl restart nginx

Deploying Your Application

Clone your Git repository into the /var/www/yourApp directory. You'll likely encounter a "Permission Denied" error, so change the ownership of the folder:

sudo chown -R ubuntu /var/www

Create a simple app.js to run your server:

var koa = require("koa")
var app = koa()

// logger
app.use(function* (next) {
  var start = new Date()
  yield next
  var ms = new Date() - start
  console.log("%s %s - %s", this.method, this.url, ms)
})

// response
app.use(function* () {
  this.body = "Hello World"
})

app.listen(3000)

Start the server:

node app.js

Open your browser and navigate to your public domain. You should see your Koa.js application running.

App Running

Done! Feel free to leave a comment below if you have any questions. :)

Deploying a Koa.js Application to an AWS EC2 Ubuntu Instance

Hello everyone, and welcome to "Continuous Improvement," the podcast where we explore different strategies and techniques for improving our skills and knowledge in the technology world. I'm your host, Victor, and in today's episode, we're going to dive into deploying a Koa.js application on an Amazon Web Services (AWS) Ubuntu server.

But before we begin, a quick reminder to subscribe to our podcast on your favorite platform and follow us on social media to stay updated on all our latest episodes. Alright, let's get started!

The first step in deploying our Koa.js application is to launch an Ubuntu instance on AWS. Now, it's important to modify the security group settings to ensure our application is accessible.

As you can see in the images provided in the blog post, it is necessary to add inbound rules for HTTP port 80 and HTTPS port 443. Without these changes, accessing the public domain in a browser would result in a "Connecting" state, eventually timing out and rendering the site unreachable.

Now that we have our Ubuntu instance set up, the next step is to install Node.js, the runtime environment for our Koa.js application. SSH into your instance and follow the official documentation instructions to install Node.js.

With Node.js successfully installed, we now move on to setting up Nginx as a reverse proxy server. Nginx will help us route traffic to our Koa.js application.

First, we need to install Nginx by running the appropriate commands. Once that's done, we'll open the Nginx configuration file and make the necessary edits, including adding the server block with the reverse proxy settings. Don't forget those semicolons!

After saving the configuration file, we need to restart the Nginx service to apply the changes.

Now that our server and reverse proxy are set up, it's time to deploy our Koa.js application. Clone your Git repository into the /var/www/yourApp directory on the Ubuntu instance. Keep in mind that you may encounter a "Permission Denied" error, but it can be easily fixed by changing the ownership of the folder.

Great! With the application files in place, it's time to create a simple app.js file to run our Koa.js server. The code in this file sets up a basic Koa.js server with a logger and a response that says "Hello World".

We're almost there! Just a few more steps. Start the server by running the node app.js command in the terminal.

And finally, open your browser and navigate to your public domain. If everything was done correctly, you should now see your Koa.js application running.

Congratulations! You've successfully deployed your Koa.js application on an AWS Ubuntu server. I hope this step-by-step guide has been helpful to you. If you have any questions or need further assistance, please feel free to leave a comment on the blog post.

That wraps up this episode of "Continuous Improvement." I hope you found the information valuable and that it inspires you to continue expanding your skills and knowledge. Don't forget to subscribe to our podcast and follow us on social media for more episodes like this one. Thanks for tuning in, and until next time, keep improving!

heroImage: '/2017-01-07.png'---

將 Koa.js 應用程式部署至 AWS EC2 Ubuntu 實例

我正在使用 Koa.js 開發一個應用程式,這是一個由 Express 團隊創建的新網頁框架。在這個逐步教學中,我將指導您如何在 Amazon Web Services (AWS) Ubuntu 伺服器上部署 Koa.js 應用程式。

在 AWS 上啟動 Ubuntu 實例

首先,在 AWS 上啟動一個 Ubuntu 實例。您需要修改安全組設定。

Security Group Settings

如果您沒有進行這些更改,試圖在瀏覽器中訪問公共域將導致“連接”狀態,直到超時,導致無法訪問網站。

Site Unreachable

默認情況下,啟動嚮導僅啟用 SSH。

SSH Only

點擊“編輯”按鈕以添加適用於 HTTP 端口 80 和 HTTPS 端口 443 的入站規則。

Edit Inbound Rules

安裝 Node.js

通過 SSH 登入您的實例並根據官方文檔安裝 Node.js:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

設置 Nginx 作為反向代理伺服器

接下來,安裝 Nginx:

sudo apt-get update
sudo apt-get install nginx

打開配置文件並進行以下編輯。別忘了分號:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/yourApp;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

保存文件並重新啟動 Nginx 服務:

sudo systemctl restart nginx

部署您的應用程式

將您的 Git 存儲庫克隆到 /var/www/yourApp 目錄。您可能會遇到“Permission Denied”錯誤,所以更改文件夾的所有權:

sudo chown -R ubuntu /var/www

創建一個簡單的 app.js 來運行您的伺服器:

var koa = require("koa")
var app = koa()

// logger
app.use(function* (next) {
  var start = new Date()
  yield next
  var ms = new Date() - start
  console.log("%s %s - %s", this.method, this.url, ms)
})

// response
app.use(function* () {
  this.body = "Hello World"
})

app.listen(3000)

啟動伺服器:

node app.js

打開您的瀏覽器並導航到您的公共域。您應該看到您的 Koa.js 應用程式正在運行。

App Running

完成!如果您有任何問題,請隨時在下面留言。:)

Lessons Learned from an IoT Project

Last year, I worked on an Internet of Things (IoT) project focused on a Bluetooth smart gadget. The experience differed significantly from pure software development in several ways:

Firstly, integration posed a challenge because the project's mechanical, firmware, mobile app, and design components were outsourced to multiple vendors. These vendors had geographically dispersed teams and varying work cultures. When developers are so specialized in their fields that they work in silos, the Scrum model is unlikely to function effectively.

Secondly, the duration of hardware iterations far exceeded that of software iterations, making it difficult to adapt to changes. Unlike software, which can be easily modularized, many hardware components like chips and motherboards are interconnected. This situation pushes the development process toward a more waterfall-like approach. You either receive the entire prototype or nothing at all; there's no middle ground for delivering a Minimum Viable Product (MVP) for consumer testing. The absence of early user feedback further hampers the feature prioritization process.

Thirdly, diagnosing issues becomes particularly challenging when things go wrong. It's difficult to determine whether the problem lies in the mechanical design, firmware, or mobile app development. Additionally, end-to-end testing becomes more complex as interfaces evolve. Conducting tests without comprehensive hardware automation was also time-consuming. To alleviate this, it's essential to have clearly defined and testable acceptance criteria, ensuring a strict definition of "done."

Effective communication is crucial for the success of any IT project, especially when various aspects aren't progressing as planned. Finger-pointing and defensiveness can severely damage interdepartmental relationships. Effective communication requires empathy; try to understand issues from the other person's perspective instead of reacting emotionally or judgmentally.

Customers assess performance based on the value they derive from a product. Adopting an empathetic and problem-solving mindset can reduce wasted time and effort, thereby improving overall performance. I look forward to the product's release and the positive reactions from its end-users.

Lessons Learned from an IoT Project

Hello, and welcome to Continuous Improvement, the podcast where we explore the challenges and triumphs of project development in the ever-evolving landscape of technology. I'm your host, Victor, and today we're discussing a topic close to my heart: the experience of working on an Internet of Things project.

Last year, I had the opportunity to work on a fascinating project focused on a Bluetooth smart gadget. But let me tell you, it was quite a departure from pure software development. Today, I want to share with you some of the unique challenges I faced and the lessons I learned along the way.

One of the major challenges I encountered was the integration of various components. You see, different aspects of the project, such as mechanical, firmware, mobile app, and design components, were outsourced to multiple vendors. And to make things even more complex, these vendors had geographically dispersed teams and different work cultures. It was like putting together a puzzle with pieces from different boxes.

When developers are so specialized that they work in silos, the standard Scrum model doesn't function as effectively. Collaboration becomes essential, and that's when effective communication truly shines.

Another hurdle I faced was the difference in duration between hardware and software iterations. Unlike software, which can be easily modularized, hardware iterations take a much longer time. This made adapting to changes and delivering a Minimum Viable Product (MVP) for consumer testing quite challenging. And without early user feedback, prioritizing features became a tough task. It almost felt like a waterfall-like approach in a fast-paced technology world.

Additionally, diagnosing issues became a puzzle of its own. With multiple components from different vendors, it was difficult to determine whether problems stemmed from mechanical design, firmware, or mobile app development. End-to-end testing also grew more complex as interfaces evolved. And without comprehensive hardware automation, testing became a time-consuming process.

So, what did I learn from these unique challenges? Well, it all comes down to effective communication and problem-solving mindset. Empathy is crucial. Instead of pointing fingers or becoming defensive, it's vital to understand issues from the other person's perspective. Building strong interdepartmental relationships is essential for the success of any IT project.

Customers judge the performance of a product based on the value they derive from it. By adopting an empathetic and problem-solving mindset, we can reduce wasted time and effort, ultimately improving overall performance.

And with that, we've reached the end of today's episode. I hope you found my insights into IoT project development valuable. Remember, embracing continuous improvement is key to succeeding in this ever-changing landscape.

Join me on the next episode of Continuous Improvement, where we'll dive into another fascinating topic. Until then, happy developing!

從物聯網項目中吸取的教訓

去年,我參與了一個專注於藍牙智能裝置的物聯網(IoT)項目。這個經驗與純軟體開發在幾個方面有顯著的不同:

首先,集成帶來了挑戰,因為項目的機械設計、固件、手機應用程式和設計組件被分包給多個供應商。這些供應商有地理上分散的團隊和不同的工作文化。當開發人員在他們的領域專門化到組織成獨立的群體時,Scrum模型不太可能有效運行。

其次,硬體迭代的時長遠超過軟體迭代,使其難以適應變化。與軟體不同,軟體可以輕易被模塊化,許多硬體組件如晶片和主機板卻是相互關聯。這種情況推動了開發過程向著更像瀑布模型的方向。你只能收到整個原型或者一無所有;沒有傳遞一個用於消費者測試的最小可行產品(MVP)的中間地帶。早期用戶反饋的缺乏進一步阻礙了特性優先級的確定過程。

第三,當事情出錯時,診斷問題尤其具有挑戰性。很難確定問題是出在機械設計、固件還是手機應用程式的開發。此外,隨著介面的演變,端到端的測試變得更加複雜。在沒有全面的硬體自動化的情況下進行測試也很耗時。為了緩解這一點,有必要明確並可驗證的接受準則,確保“完成”的嚴格定義。

對任何IT項目的成功而言,有效的溝通至關重要,特別是當各個方面沒有按計劃進展時。指責和防衛可以嚴重損害部門之間的關係。有效的溝通需要同理心;嘗試從他人的角度理解問題,而不是情緒化或判斷式地反應。

客戶根據他們從產品中獲得的價值來評估性能。採取同理心和解決問題的思維方式可以減少浪費的時間和精力,從而提高整體性能。我期待著產品的發佈和最終用戶的積極反饋。

How to Fix iOS 10 Permission Crash Errors

I've been developing an app that requires access to the user's microphone.

The app worked fine on iOS 9, but after upgrading to iOS 10, it started crashing. The error message displayed in the terminal reads as follows:

> This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data.
> (lldb)

To resolve this issue, edit the Info.plist file as source code and add the following lines:

    <key>NSMicrophoneUsageDescription</key>
    <string>Provide a description explaining why your app needs microphone access.</string>

Additionally, if your app needs access to the user's camera, add the following:

    <key>NSCameraUsageDescription</key>
    <string>Provide a description explaining why your app needs camera access.</string>

If your app requires access to the user's contacts, add this:

    <key>NSContactsUsageDescription</key>
    <string>This app requires access to your contacts.</string>

Happy coding!

How to Fix iOS 10 Permission Crash Errors

Welcome to Continuous Improvement, the podcast where we delve into the world of app development and discuss common issues developers face on a regular basis. I'm your host, Victor, and in today's episode, we're going to address a problem that many of us have encountered - app crashes after an operating system update. Specifically, we'll be focusing on an error related to privacy-sensitive data access while using the microphone on iOS 10.

So, picture this: You've developed an amazing app that runs smoothly on iOS 9. Everything is going great until you make the daring decision to upgrade to iOS 10. Suddenly, your app starts crashing, leaving you puzzled and frustrated. But fear not, my fellow developers! I am here to guide you through this ordeal.

The error message that appears in the terminal states, "This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data." Quite a mouthful, right?

The solution is quite straightforward. To resolve this crash caused by microphone access, we need to make a quick edit in the Info.plist file. Essentially, we'll be adding a description about why our app needs microphone access, so that it complies with iOS 10's privacy requirements.

So, let's jump into it. Open your Info.plist file as source code and insert the following lines:

    <key>NSMicrophoneUsageDescription</key>
    <string>Provide a description explaining why your app needs microphone access.</string>

By adding this snippet to your Info.plist file, you're providing a clear message to users about why your app requires microphone access. This is a crucial step to ensure compliance with iOS 10's privacy rules.

Now, let's not forget about potential crashes related to camera or contacts access. If your app requires these permissions, be sure to include the appropriate lines in your Info.plist file as well.

For camera access:

    <key>NSCameraUsageDescription</key>
    <string>Provide a description explaining why your app needs camera access.</string>

And for contacts access:

    <key>NSContactsUsageDescription</key>
    <string>This app requires access to your contacts.</string>

Remember, providing users with clear and concise explanations for why your app needs these privacy-sensitive permissions is vital to maintaining user trust and satisfaction.

And that's it! By making these edits, you'll be able to successfully prevent crashes caused by privacy-sensitive data access after updating to iOS 10.

Well, that's all for today's episode. I hope you found this information useful and it helps you overcome the microphone access crash issue.

If you have any questions or topics you'd like me to cover in future episodes, feel free to reach out to me on Twitter @VictorDev.

Thanks for tuning in to Continuous Improvement. Until next time, happy coding!

如何修復 iOS 10 權限崩潰錯誤

我一直在開發一款需要訪問用戶麥克風的應用程序。

該應用在 iOS 9 上運行正常,但在升級到 iOS 10 之後,它開始崩潰。終端顯示的錯誤消息如下:

> 此應用程序已崩潰,因為它試圖訪問隱私敏感數據而未提供使用說明。應用程序的 Info.plist 必須包含一個 NSMicrophoneUsageDescription 鍵,並提供一個字符串值解釋應用程序如何使用這些數據。
> (lldb)

要解決此問題,按源碼編輯 Info.plist 文件並添加以下行:

    <key>NSMicrophoneUsageDescription</key>
    <string>提供一個說明,解釋您的應用為何需要訪問麥克風。</string>

此外,如果您的應用需要訪問用戶的相機,請添加以下內容:

    <key>NSCameraUsageDescription</key>
    <string>提供一個說明,解釋您的應用為何需要訪問相機。</string>

如果您的應用需要訪問用戶的聯繫人,請添加以下內容:

    <key>NSContactsUsageDescription</key>
    <string>此應用需要訪問您的聯繫人。</string>

祝你編碼愉快!

The Future of FinTech in Hong Kong

I was often told by my teachers that Hong Kong is an international financial center. Indeed, in our highly competitive corporate environment, we enjoy economic success daily. However, Hong Kong currently lags in the FinTech revolution. Singapore has seized this opportunity and has aggressively moved ahead. The Singaporean government has played a crucial role in attracting FinTech companies by providing incentives and clear regulations. Moreover, the extensive client base available to mainland China's FinTech firms has enabled them to thrive in ways that Hong Kong companies haven't.

The challenge is clear: Hong Kong's risk-averse mentality is slowing the progress of the FinTech industry. As an IT consultant, I've heard numerous individuals in the banking sector express concerns about innovations like blockchain, Bitcoin, and mobile payments. They fear these technologies could disrupt their businesses, jeopardize jobs, and result in big companies failing to adapt.

However, there's a silver lining: Hong Kong is home to a large number of innovative and creative individuals. Our community boasts a diverse group of thinkers, builders, and leaders. We have the potential to assemble outstanding teams that can inspire and contribute to the creation of the world's best FinTech ecosystem. Now is the time to elevate our awareness and reimagine what is possible when financial technology serves as a catalyst for positive industry transformation.

In my opinion, this is the desired outcome: we are guiding global financial technology to become more human-centered. Our current legal sandbox policy allows companies to test their innovative ideas in the marketplace. These financial technologies have the potential to positively impact people's lives around the globe. Together, let's utilize the language and tools of FinTech to reestablish Hong Kong as the regional hub for FinTech commerce.