引入主模块(babel-register、babel-preset-es2015 )
yarn add babel-register babel-preset-es2015 --dev
创建启动js文件(start.js)和服务文件(server.js)
//start.js
require('babel-register') ({
presets: [ 'es2015' ]
})
module.exports = require('./server.js')
//server.js
import Koa from 'koa'
const app = new Koa()
app.use(ctx =>{
ctx.body = 'node use import/export success!!!'
})
app.listen(3000, ()=>{
console.log('server is running on http://localhost:3000')
})