Introduction to Koa Js
What is koa js?
Koa.js is a flexible Node.js web application framework that provides robust web and mobile application features. Koa.js is a lightweight framework for building web apps and APIs. The framework’s features and technologies help programmers simplify the creation of web apps and APIs.
Let’s create a sample project using Koa.js
- Before we start to develop, we need to have installed Node and npm. Using this link we can install Node.js, https://nodejs.org/en/download/
Node Package Manager (npm)
- Using the following command you can check the installed version on node and npm.
> node --version
> npm --version
- You will get output like this,
Let’s go on the step by step.
- Here I used vs code to run this program. Create a new folder named hello-world.
- Open new ‘Terminal’ and run the following code to create a package.json file,
- It will request the following information from you.
- To install koa run the following code,
npm install koa
- To install nodemon run the following code,
npm install nodemon --save-dev
- Create a new file called app.js and type the following code,
var koa = require('koa');
var app = new koa();
this.body = 'Hello world!';
console.log('Server running on https://localhost:3000')
- Save the file and type the following code in terminal,
- This will start the server. To test this app, go to https://localhost:3000 in your browser and you should see the following message.
Hope you learned something from this article.