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

lorenzopicoli/node-api-starter: Node.js API server starter using Koa and Bookshe ...

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

开源软件名称:

lorenzopicoli/node-api-starter

开源软件地址:

https://github.com/lorenzopicoli/node-api-starter

开源编程语言:

JavaScript 100.0%

开源软件介绍:

Node API Starter CircleCI

Dependencies codecov Code Climate

Stack

Getting started

Clone the repository:

git clone https://github.com/lorenzopicoli/node-api-starter.git

Navigate to the repo folder and install the dependencies:

npm i

Env variables will be loaded from a .env file (see Environment section)

touch .env

You can make sure the code is working by running the server on development mode:

➜ npm run dev

You should get back:

> [email protected] dev /Users/lorenzopicoli/WebDev/node-api-boilerplate
> NODE_ENV=development ./node_modules/.bin/nodemon index.js

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
Server running on 5000

Creating new modules

Let's call it places:

# Create the module folder
mkdir src/modules/places
touch src/modules/places/controller.js
touch src/modules/places/router.js

# Create the bookshelf model file
touch src/models/places.js

# Create the database migration file
knex migrate:make create_places_table

# Run the new migration
npm run db:migrate

Environment variables

.env example:

PORT=5000
DATABASE_URL=postgresql://localhost:5432/<db name>
AWS_BUCKET=xxxxxxx
AWS_ACCESS_KEY_ID=XXXXXXXX
AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxx
CODECOV_TOKEN=xxxxxxxxxxx
ADMIN_PASS=xxxxxxxx (admin password for seeding)
FACEBOOK_ID=xxxxxxxxx
FACEBOOK_SECRET=xxxxxxx

NPM scripts

Start the server on live mode (and migrate the database)

npm start

Start the server for development (live reload)

npm run dev

Before commit (lint and execute tests)

npm run commit

Generate documentation

npm run docs

Run tests

npm test

Documentation

API documentation is written inline and generated by jsondoc.

Example: https://lorenzopicoli.github.io/node-api-starter

Migrations & Seeding

Generate new migration

knex migrate:make migration_name

Run migrations

knex migrate:latest

Roll back migration

knex migrate:rollback

Run seeds

# development or production environment
NODE_ENV=development knex seed:run

See knex docs for details

License

MIT




鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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