Welcome to Koa(tutorial -02)
In here we are talking about how to create a server using koa.js
First of all we should install node.js to computer. then we can see node version using command prompt. after opening prompt we should type node -v and press enter the we can see node version.
after that we should make a directory or new folder and open a terminal using visual code of any other code editor. then we should create package.json for that directory or the folder.
in next step we may type npm init in terminal and answer certain questions as follows.
In next step we should install koa and nodemon to pc. for that we also type npm install koa and npm install -g nodemonin command prompt and hit enter.
then we should make a new JS file(app.js) and add start and dev command in package.json as below
next we type our code in app.js file.
after that step we should run that using npm run dev
then we can see our message in our port. we can go that using localhost:3200
And main thing is Koa don’t came with a inbuild router so we have to install koa router as well. for that we have to type npm i koa-router
After that we can use that as middleware. so we can edit app.js file below as well.
After running the code we can also see same message in our port.