Use Import command in Node.js

前端 未结 1 571
旧巷少年郎
旧巷少年郎 2021-01-06 14:33

I have this node package installed https://github.com/jakearchibald/indexeddb-promised/blob/master/lib/idb.js, and am trying to use it.

I am trying to use this comm

1条回答
  •  一整个雨季
    2021-01-06 15:09

    You can use babel to transpile your code in ES6 syntax to ES5 in a transparent way for your develop. This is a part of my package.json in a demo app

     {
      "name": "**********",
      "version": "1.0.0",
      "description": "",
      "main": "server.js",
      "scripts": {
        "start": "nodemon server.js --exec babel-node --presets es2015,stage-2"
      },
      "author": "Borja Tur",
      "license": "ISC",
      "dependencies": {
        "bcrypt-nodejs": "0.0.3",
        "body-parser": "^1.15.1",
        "express": "^4.13.4",
        "jsonwebtoken": "^7.0.0",
        "mongoose": "^4.4.19",
        "morgan": "^1.7.0"
      },
      "devDependencies": {
        "babel": "^6.5.2",
        "babel-cli": "^6.9.0",
        "babel-preset-es2015": "^6.9.0",
        "babel-preset-stage-2": "^6.5.0"
      }
    }
    
    1. Install the same "devDependencies"
    2. Install nodemon globally "npm install nodemon -g"
    3. Configure your npm start command with the same of my package.json changing "server.js" with your entry file in the app
    4. Run "npm start"

    Then you can use import syntax

    0 讨论(0)
提交回复
热议问题