从express.Router()导入路由器

时间:2018-04-16 14:56:55

标签: node.js express

我在 index.js

之上
import express from 'express'
import favicon from 'serve-favicon'
import router from express.Router()

我一直在

[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `babel-node ./index.js`
/Users/bheng/Desktop/express-app/node_modules/babel-core/lib/transformation/file/index.js:590
      throw err;
      ^

SyntaxError: /Users/bheng/Desktop/express-app/index.js: Unexpected token (3:19)
  1 | import express from 'express'
  2 | import favicon from 'serve-favicon'
> 3 | import router from express.Router()
    |                    ^

这是什么语法?我做错了什么 ?

enter image description here

1 个答案:

答案 0 :(得分:3)

您已导入快递,因此要访问Router您不再需要导入。

const router = express.Router();