api-server

用 Node.js 写个 api server,需求

  • 使用 ES2015 and beyond, babel-preset-latest
  • 使用展开运算符 ..., babel-plugin-transform-object-rest-spread
mkdir apiServer && cd apiServer
npm init -y

Install the CLI ,this preset and plugin:

npm install --save-dev babel-cli babel-preset-latest babel-plugin-transform-object-rest-spread

Make a .babelrc config file with the preset and plugin

echo '{ "presets": ["latest"],"plugins": ["transform-object-rest-spread"] }' > .babelrc

Install nodemon

npm install --save-dev nodemon

Install babel-node:

yarn global add babel-cli

向 package.json 添加 npm script

...
 "script": {
    "dev": "nodemon --exec babel-node src/index.js",
    "prestart": "babel src --out-dir dist",
    "start": "node dist/index.js"
  }
...

项目目录结构如下

-- apiServer
 |-build
 |-src
 |-.babelrc
 |-package.json

其他需要的包

  • express
  • body-parser