• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

pranavpr/koa2-es2017-api-boilerplate:

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

pranavpr/koa2-es2017-api-boilerplate

开源软件地址:

https://github.com/pranavpr/koa2-es2017-api-boilerplate

开源编程语言:

JavaScript 100.0%

开源软件介绍:

Rest API boilerplate using Koa2 & ES2017

CircleCI Coverage Status dependency Status devDependency Status License

A mostly unopinionated starter project for creating RESTful APIs using Koa2 and ES2017+ features in a Node.js server environment as well as providing linting and testing support. It provides the setup for compiling, linting and testing your code but doesn't make any further assumptions on how your project should be structured.

Make sure you read the FAQ for more details and info.

Features:

Getting started

# Clone the project
git clone [email protected]:pranavpr/koa2-es2017-api-boilerplate.git
cd koa2-es2017-api-boilerplate

# Make it yours
rm -rf .git && git init && npm init

# Install dependencies
npm install

# or if you're using Yarn
yarn

If you don't use Yarn you can just replace yarn with npm in the commands that follow.

Then you can begin development:

yarn run dev

This will launch a nodemon process for automatic server restarts when your code changes.

Testing

Testing is powered by Jest. This project also uses supertest for demonstrating a simple routing smoke test suite. Feel free to remove supertest entirely if you don't wish to use it.

Start the test runner in watch mode with:

yarn test

You can also generate coverage with:

yarn test --coverage

Linting

Linting is set up using ESLint. It uses ESLint's default eslint:recommended rules. Feel free to use your own rules and/or extend another popular linting config (e.g. airbnb's or standard).

Begin linting in watch mode with:

yarn run lint

Environmental variables in development

The project uses dotenv for setting environmental variables during development. Simply copy .env.example, rename it to .env and add your env vars as you see fit.

It is strongly recommended never to check in your .env file to version control. It should only include environment-specific values such as database passwords or API keys used in development. Your production env variables should be different and be set differently depending on your hosting solution. dotenv is only for development.

Deployment

Deployment is specific to hosting platform/provider but generally:

yarn run build

will compile your src into /dist, and

yarn start

will run build (via the prestart hook) and start the compiled application from the /dist folder.

The last command is generally what most hosting providers use to start your application when deployed, so it should take care of everything.

FAQ

Where is all the configuration for ESLint, Jest and Babel?

In package.json. Feel free to extract them in separate respective config files if you like.

Why are you using @babel/register instead of @babel/node?

@babel/node contains a small "trap", it loads Babel's polyfill by default. This means that if you use something that needs to be polyfilled, it'll work just fine in development (because @babel/node polyfills it automatically) but it'll break in production because it needs to be explicitely included in Babel's CLI which handles the final build.

In order to avoid such confusions, @babel/register is a more sensible approach in keeping the development and production runtimes equal. By using @babel/preset-env only code that's not supported by the running environment is transpiled and any polyfills required are automatically inserted.

License

MIT License. See the LICENSE file.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap