npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@c42/feathers-a

v0.1.3

Published

基于 [express](https://expressjs.com)、[feathersjs](https://feathersjs.com/) 和 [@c42/commons](https://code.aliyun.com/c42/commons) 的后端项目样板

Downloads

5

Readme

c42-template-feathers

基于 expressfeathersjs@c42/commons 的后端项目样板

安装

按照 克隆项目 的提示,克隆本项目到本地,并 copy 到你真正的开发目录。

注意不要 copy /.git 目录,否则会把你真正开发项目的 .git 目录覆盖掉。

如果要使用 linux cp 命令移动项目,注意要加 -a 参数,以防遗漏隐藏文件。

克隆并 copy 完毕之后,进入你的开发项目目录,运行 yarn 进行初始化安装。

强烈建议使用 yarn 代替 npm

开发

yarn dev # 以 src/index.js 为入口,利用 nodemon 实现热加载

lint

npm run lint # 运行 eslint

每次 git commit 时都会自动先执行 yarn lint,所以 commit 一般会花十几秒钟才能完成。

如果 lint 不通过,则拒绝 commit。

构建

yarn build # 构建并打开构建报告 .build.report.html

为什么后端也需要构建?因为 dev 时用 babel-register 实时转化 es6 语法的效率较低。backpack/webpack 打包后执行效率稍高。

  1. 如果开发的是一个完整的后端 app,不应该存在 src/export.js。此时构建以 src/index.js 为入口。
  2. 如果开发的是一个需要对外发布的 vue 组件,应该存在 src/export.js。此时构建以 src/export.js 为入口。

请注意,src/export.js 文件是否存在,决定了构建的入口以及其他很多具体行为。src/export.js 非常重要!

打包得到的 bundle 文件位置: ./dist/main.js。其中并不包含 node_modules 里面的模块。

构建完成后相关报告会保存在 .build.report.html 中。

Caveats

backpack 打包之后 __dirname__filename 等和运行环境路径相关的变量的值的含义会发生变化,所以请避免在代码中使用 __dirname__filename

生产

yarn start

如果开发的是一个模块,则 yarn start 命令没有意义。

发布

如果开发的是一个需要对外发布的 middleware、service 等模块,由 src/export.js 指定哪个文件是要对外发布的模块的入口。发布流程为:

npm version major|minor|patch # 发布前要先根据本次修改的性质升级版本号
npm publish # 之前需要先注册并登录 npmjs.com 帐号,并确保正在使用 npmjs.com 官方源。可以使用 nrm 来切换源。

如果开发的是一个完整的 app,则并不存在发布这个概念。在此情况下,为了防止误操作发布,请设置 package.json 中的 private 字段为 true

测试

yarn unit # 单元测试
yarn coverage # 单元测试 + 测试覆盖率统计
yarn test # 运行 eslint + 单元测试 + 测试覆盖率统计

配置

后端 feathers 配置文件:/feathers.config.js。用法详见 createApp 注释及源码。

生产环境部署常常需要通过环境变量来传入配置信息。通过设置特定环境变量,可以在不修改 feathers.config.js 源码的前提下动态指定一些配置的值。

比如,假设项目名称(即 package.json 里的 name 取值,把所有 @ 删除,再把所有 /- 替换成 _,即得到真实项目名称)为 project_a,则:

  • ~/.bashrc 中设置环境变量 export PROJECT_A_PROD_PORT=1234,即可动态指定生产环境(yarn start)下的端口为 1234

  • ~/.bashrc 中设置环境变量 export PROJECT_A_DEV_MONGODB="someurl",即可动态指定开发环境(yarn dev)下的 mongodb 地址为 someurl

  • ~/.bashrc 中设置环境变量 export PROJECT_A_TEST_FAVICON="somepath",即可动态指定测试环境(yarn unityarn coverageyarn test)下的 favicon 路径为 somepath

至于具体哪些配置项可由环境变量所动态指定,请见 feathers.config.js 源码中包含 getEnv(...) 的部分。

调试

  1. 程序内分级 log

    app.log('info', 'xxxx')
    app.error('xxxx')
    app.warn('xxxx')
    app.info('xxxx')
    app.debug('xxxx')

    log 的具体显示可由 C42_LOG_LEVEL, C42_LOG_PRETTY and C42_LOG_TIME 这三个环境变量控制:

    C42_LOG_LEVEL=info C42_LOG_PRETTY=true C42_LOG_TIME=true npm start

    C42_LOG_LEVEL=error|warn|info|verbose|debug|silly: 调用 app[level]() 时,只有级别高于 C42_LOG_LEVEL 的 log 可以显示。error 是最高级,silly 是最低级。默认级别为 silly,也就是默认所有级别的 log 都显示。

    C42_LOG_PRETTY=true:美化显示,但是会占用更多的行数。默认 false

    C42_LOG_TIME=true:显示时间。默认 false

  2. 自动 log 所有的中间件 request 和钩子 context 信息

    使用环境变量 C42_LOG_ALL=true。** 严重影响性能,仅用于调试,禁止用于生产环境!**

    C42_LOG_ALL=true C42_LOG_TIME=true npm dev

    or

    C42_LOG_ALL=true C42_LOG_LEVEL=debug npm test

    也可以只自动 log 所有中间件 request,比如:

    C42_LOG_ALL_REQUESTS=true npm dev:server

    或只自动 log 所有钩子 context,比如:

    C42_LOG_ALL_CONTEXTS=true npm dev
  3. 自动进行性能 profiling

    C42_PROFILER=true npm start

    or

    C42_PROFILER=true C42_PROFILER_STATS=total npm start

    此时可以使用 app.get('profiler').print() 方法打印 profiler 统计信息。

前置知识