Questions tagged [koa]

Koa is a web framework which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs.

Koa is a web framework for Node.js, designed by the team behind Express, aiming to be a smaller, more expressive, and more robust foundation for web applications and APIs.

Use this tag if your question is about the application middleware generators and its cascading properties or the use of App.Settings. Note also the existence of the tag if you're using the middleware API with async/await.

Resources

1232 questions
9
votes
4 answers

Initiate file download with Koa

I'm using Koa as a webserver to serve my Polymer application. Upon pressing a button in the frontend localhost:3000/export is called. I would like to deliver a file-download to the client after packing the some files to a zip-archive. How to do this…
Hedge
  • 16,142
  • 42
  • 141
  • 246
9
votes
1 answer

Writing a streaming response from a streaming query in Koa with Mongoose

I'm trying to send a large result-set from a Mongo database to the user of a Koa application (using Mongoose). I originally had something like: var res = yield Model.find().limit(500).exec(); this.body = {data: res}; However, the size of the result…
9
votes
2 answers

How correctly use Redis with Koa (node.js)

I try to get an information from a redis db and return it as the body of the response to the user. First, here is a code that fails : var redis = require("redis"), koa = require("koa"); var app = koa(), port = process.argv[2] || 3000, …
AntoineKa
  • 185
  • 1
  • 6
9
votes
5 answers

automatically reloading Koa server

I've started playing around with Koa, but so far have been unable to find a decent solution for automatically reloading the application upon code changes. My understanding is that nodemon is the preferred solution in the Node universe, but I'm…
AnC
  • 4,099
  • 8
  • 43
  • 69
8
votes
1 answer

What is modern way to hosting `node.js` applications on Windows 10 and Windows Server 2012 and newer?

I want to know how to deploy my node.js application (it uses Koa) on Windows 10, Windows server 2012 and newer. In Internet I see old tips for using iisnode, but at the same time I see that people worry that developers no answer for many important…
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182
8
votes
1 answer

docker-compose: nodejs + mysql can't connect mysql

I try to dockerlized my own node application, but can't connect the mysql container. my codes: docker-compose.yml version: '3.2' services: node: build: ./ ports: - "8787:8787" depends_on: - db …
ycjcl868
  • 432
  • 3
  • 7
  • 18
8
votes
1 answer

Koa.js and streaming. How do you handle errors?

Does anybody works with koa.js and streams? Consider this example const fs = require('fs'); const Koa = require('koa'); const app = new Koa(); app.use(async (ctx) => { ctx.body =…
Stepan Kuzmin
  • 1,031
  • 2
  • 11
  • 21
8
votes
1 answer

Node JS - Nginx - proxy_pass to a subdirectory - Koa

I'm running a Koa app on port 5000, and i'd like Ngnix to serve the app in a sub-directory - e.g: http://example.com/myNodeApp Here's what I've currently got in /etc/nginx/sites-enabled/default location ^~ /myNodeApp/ { …
ash
  • 1,224
  • 3
  • 26
  • 46
8
votes
1 answer

How to Make a Call to Koa.js App Instance for Unit Tests

I don't know how I'd term this maybe 'static call to a koa router'? Does that seem like the right wordage here for what I'm really trying to accomplish if you were to talk about it technically? Anyway, I'm using koa-router and I'm coding unit tests…
PositiveGuy
  • 17,621
  • 26
  • 79
  • 138
7
votes
1 answer

Socket.io Client: Always invalid namespace message

Server code: import http from 'http'; import Koa from 'koa'; import { Server } from 'socket.io'; (async () => { const app = new Koa(); var server = http.createServer(app.callback()); var io = new Server(server, { path: '/seacher', …
user1356144
  • 103
  • 1
  • 1
  • 7
7
votes
1 answer

I get a webpack warning Critical dependency: the request of a dependency is an expression when use koa

When I start webpack for bundling my react application using koa with server side rendering I get a warning WARNING in /app/node_modules/any-promise/register.js 24:14-37 [1] Critical dependency: the request of a dependency is an expression [1] @…
user9487500
7
votes
0 answers

Getting "bad-precaching-response " error after service worker registeration is successful

In my project, I am using NextJS+KOA+Apollo. My nextJS app is inside client in root directory. I am using next-offline to convert it to PWA. Nextjs app is inside client directory. koa server is inside server directory. when i am building the app via…
RiksAndroid
  • 815
  • 11
  • 17
7
votes
1 answer

How to use GraphQL subscription correctly?

I have a GraphQL powered app. The query and mutation parts work well. I try to add GraphQL subscription. The server GraphQL subscription part code is inspired by the demo in the readme of apollographql/subscriptions-transport-ws. Please also check…
Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267
7
votes
2 answers

How to make koa ctx.throw() use application/json rather than text/plain

I have made a custom error handler for my koa app which works beautifully (except for one sticking point) - using ctx.throw() means any stacktrace is emitted to the server logs and also any custom error message is sent in the response. The one…
Yorkshireman
  • 2,194
  • 1
  • 21
  • 36
7
votes
4 answers

How to wait for a url callback before send HTTP response in koa?

I have a koa router I need to call a api where will async return result. This means I cannot get my result immediately, the api will call my callback url when it's ok. But now I have to use it like a sync api which means I have to wait until the…
roger
  • 9,063
  • 20
  • 72
  • 119