question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to run koa with nodejs v6.11.2

See original GitHub issue

Nodejs version 6.11.2 is LTS.So I need to use this nodejs version to run koa2.I followed tutorial and code is:

require('babel-register');
const Koa = require('koa');
const app = new Koa();

app.use(async ctx => {
    ctx.body = 'Hello World';
});

app.listen(3000);

Package.json:

{
  "name": "koa",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "dependencies": {
    "babel-cli": "^6.24.1",
    "babel-plugin-transform-async-to-module-method": "6.24.1",
    "babel-register": "6.24.1",
    "koa": "2.3.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

But it didn’t say how to run app.js?

I try node app.js and it did not work. Any helps?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
fl0wcommented, Aug 7, 2017

This works for me.

index.js

require('babel-core/register')
require('babel-polyfill')
require('./app.js')

app.js

'use strict'

const Koa = require('koa')
const app = new Koa()

app.use(async ctx => {
  ctx.body = 'Hello World'
})

app.listen(3000)

.babelrc

{
  "presets": [
    "node6"
  ],
  "plugins": [
    ["transform-async-to-module-method", {
        "module": "bluebird",
        "method": "coroutine"
    }]
  ]
}

package.json

{
  ...
  "dependencies": {
    "babel-plugin-transform-async-to-module-method": "^6.24.1",
    "babel-polyfill": "^6.23.0",
    "babel-preset-node6": "^11.0.0",
    "babel-register": "^6.24.1",
    "bluebird": "^3.5.0"
  }
}
0reactions
jonyrockcommented, Jun 18, 2018

You can compile project with webpack to server.js and then compile it again with preset with target to node 6.11.2

Sorry, I don’t have time to make a simple clear solution, but you can try do digg code: https://github.com/hastic/hastic-server/blob/9000adefcc79e48e45089f9d25960f7805a37e48/server/package.json

Also I can’t say that it is the BEST solution, but it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Build a "Hello World" Application with Koa
Node.js installed locally, which you can do by following How to Install Node.js and Create a Local Development Environment.
Read more >
Koa - next generation web framework for node.js
Koa requires node v12 or higher for ES2015 and async function support. You can quickly install a supported version of node with your...
Read more >
nodejs_qinzhao168的博客 - CSDN博客
mac nodejs升级到最新版本,node点滴,node 之二进制安装方法,nodejs.
Read more >
Node.js Notes for Professionals | IERTEC
Section 1.4: Installing and Running Node.js. 6 ... Section 11.2: Get the names of the events that are subscribed to ... Chapter 61:...
Read more >
Online Node.js Compiler - Tutorialspoint
11.2) helps you to Edit, Run and Share your Node Code directly from your browser. This development environment provides you version Node v6.11.2....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found