Skip to content

jiayisheji/nest-cnode

Repository files navigation

nest-cnode

Nest Logo

Description

This is using the Nestjs imitation Cnode.

Installation

Currently runs with:

  • nodejs v8.11.1
  • mongodb v3.4.1
  • redis v3.2.1
  • nestjs v6.11.11

With this sample, you can :

  • Understand basic use of Nestjs, and store data with mongodb and redis
  • Use Nestjs with passport for authentication and third-party login Github

Getting Started

Environment Dependencies:

Clone this repository locally :

git clone https://github.com/jiayisheji/nest-cnode.git

Install dependencies with npm :

npm install

Set up .env file

You also need to set the env config.

For that, if you just create a file named .env in the directory and set the values like the following, the app will just work:

.env file

#
# config
#
HOST='localhost'
PORT=3000
STATIC_HOST=''
MINI_ASSETS=false

#
# system
#
SUPER_ADMIN='super_admin'
SESSION_SECRET='cnode'
AUTH_COOKIE_NAME='nest_cnode'
GITHUB_CLIENT_ID=myCoolClientId
GITHUB_CLIENT_SECRET=myCoolSecret

#
# access qn
#
QN_ACCESS_KEY='your access key'
QN_SECRET_KEY='your secret key'
QN_BUCKET='your bucket name'
# 如果vps在国外,请使用 http://up.qiniug.com/ ,这是七牛的国际节点
# 如果在国内,此项请留空
QN_UPLOAD_URL=''

#
# Multer upload dest
#
# 开发上传的src 生成上传dist
UPLOAD_LOCATION='src'

#
# mail
#
MAIL_HOST='smtp.126.com'
MAIL_PORT=25
MAIL_USER='[email protected]'
MAIL_PASS='club'

#
# database redis
#
# Redis Replica Set
REDIS_HOST='127.0.0.1'
REDIS_PORT=6379
REDIS_PASSWORD=''
REDIS_DB=0

#
# database mongoDB
#
# MongoDB Replica Set
MONGO_HOST="localhost"
MONGO_PORT=27017
MONGO_USER="cnode_admin"
MONGO_PASS="123456"
MONGO_DBS="db_cnode"

Running the app

# development
$ npm run start

# watch development mode
$ npm run start:dev

# production mode
 npm run prestart:prod && npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Dependencies

Dependencies are managed through package.json. In that file you'll find two sections:

dependencies

Package Description
bcryptjs Library for hashing and salting user passwords
dotenv Loads environment variables from .env file
ejs-mate Ejs template engine for Express
ioredis Redis ODM
mongoose MongoDB ODM
nodemailer Node.js library for sending emails
passport Simple and elegant authentication library for node.js
passport-local Sign-in with Username and Password plugin
passport-github Sign-in with Github plugin
typescript JavaScript compiler/type checker that boosts JavaScript productivity

devDependencies

Package Description
@types Dependencies in this folder are .d.ts files used to provide types
cross-env Cross platform setting of environment scripts
jest Testing library for JavaScript
nodemon Utility that automatically restarts node process when it crashes
supertest HTTP assertion library
ts-jest A preprocessor with sourcemap support to help use TypeScript wit Jest
ts-node Enables directly running TS files. Used to run copy-static-assets.ts
tslint Linter (similar to ESLint) for TypeScript files

Reference

  1. Awesome Nest
  1. NestJS Samples