Using Import In NodeJS server

前端 未结 2 393
孤街浪徒
孤街浪徒 2020-12-23 23:25

At the moment all my module in my nodejs server are imported as require() ie:

let path = require(\'path\');
let express = require(\'express\');
let http = re         


        
2条回答
  •  醉酒成梦
    2020-12-24 00:01

    It works in the webpack situation because the code is run through babel. You can run your node.js code through babel.

    Install the babel cli if you don't have it

    npm install --save-dev babel-cli
    

    Then run your code like this:

    ./node_modules/.bin/babel-node server.js
    

    Or put it in package.json.

    {
      "scripts": {
        "start": "babel-node server.js"
      }
    }
    

提交回复
热议问题