Code Monkey home page Code Monkey logo

sb-clean-blog-node's Introduction

SB Clean Blog Node

Build Status

Links

Click here for the frontend. Built with Angular

Click here to view Angular code coverage

Click here to view Node code coverage

Prerequisites

Before you begin, make sure your development environment inlcudes the following technologies:

1) Node.js

We recommend you use the latest LTS version of node, which is currently 12.x

To get node, go to nodejs.org

To check your node version run the following in terminal:

node --version

2) Postgres

Our Chosen ORM in Node is TypeORM. TypeORM suports most major databases

We prefer the very popular and open source postgres.

If desiered it should be relatively trivial to switch databases.

Note: db scripts at scripts/db/ have not been tested with any other databases besides postgres

To get postgres, go to postgresql.org or install via homebrew

Note: If you install via homebrew, don't forget to run brew services start postgresql

To check your postgres version run the following in terminal:

psql --version

To set up a new user in postgres type the following in terminal (It will prompt you for a password):

createuser newuser --pwprompt --createdb # newuser can be any username you choose

NOTE: Remember the username password you use here. You will need to add it into .env

Test that you can log in to postgres:

psql -U newuser template1

Common postgres commands can be found in: NOTES/POSTGRES.md

Quick Start

Download the repo

git clone [email protected]:startbootstrap/sb-clean-blog-node.git
cd sb-clean-blog-node

1) Set up .env

cp .env.sample .env

Open .env and change the values for:

DB_ROOT_USER_PASSWORD=CHANGE_ME__STRING # make up a password
TYPE_ORM_USERNAME=CHANGE_ME__STRING # postgres username
TYPE_ORM_PASSWORD=CHANGE_ME__STRING # postgres password
JWT_SECRET=CHANGE_ME__STRING # make up a random string

2) Install dependencies

npm install

3) Reset the database

This command:

  • drops the current database
  • recreates the databse
  • runs all migrations
  • creates the root user
  • seeds the db with random posts
npm run db:reset # See the next command if you have issues with this command

If you receive an error function uuid_generate_v4() does not exist then run the command:

npm run db:uuid

This will add the extension uuid-ossp to the template1 databse.

You will then need to run npm run db:reset again

4) Start the server

npm start

You should be able to hit http://localhost:8200/api/latest/health

5) Run the front end (sb-clean-blog-angular)

Follow the README at sb-clean-blog-angular

Tests

Unit Tests are named *.test.ts and are located in the same directory as the file they are testing.

Unit Tests

npm run test

# To keep the test runner going as you devleop tests use:
npm run test:watch

To run a specific test, you can do:

npm run test:one -- -t=[string]

View Coverage

npm run serve:coverage

Migrations

# typeOrm cli help
npm run cli -- -h

# Create a migration
npm run db:migration:generate -- -n my-migration

# Run migrations 
npm run db:migration:run

Docker

SB Clean Blog Node comes with a Dockerfile and build scripts.

You can get Docker here

# Be sure to build the app first
npm run build

# Then build the docker image
npm run docker:build

# Then run the image
npm run docker:run

If you intend to use this in production, you will need to modify the run script: scripts/docker/docker-run.ts to change the .env variables to point to your production postgres instance.

You will also need to develop a way to initialize and run migrations on the production database. One option is to set you local .env to temporarily point to your production database and run the commands locally.

Style

Lint Code

npm run lint

Fix all fixable lint errors

npm run lint:fix

Check if any tslint rules conflick with prettier

npm run lint:check

Debug

To run in debug mode

npm run debug

To debug tsonfig

node_modules/.bin/tsc --showConfig -p ./src/tsconfig.app.json
node_modules/.bin/tsc --showConfig -p ./src/tsconfig.spec.json

sb-clean-blog-node's People

Contributors

initplatform avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sb-clean-blog-node's Issues

Can not find module "bycrpt"

Hi there,

First, thanks for this awesome blog :)

during the step "npm run db:reset" i recive following error:

Error: Cannot find module 'bcrypt'
Require stack:

  • C:\Projekte\sb-clean-blog-node\src\lib\util\seed-db.ts
  • C:\Projekte\sb-clean-blog-node\src\lib\util\index.ts
  • C:\Projekte\sb-clean-blog-node\scripts\db\db-seed.ts
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
    at Function.Module._resolveFilename (C:\Projekte\sb-clean-blog-node\node_modules\tsconfig-paths\lib\register.js:75:40)
    at Function.Module._load (internal/modules/cjs/loader.js:898:27)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)
    at Object. (C:\Projekte\sb-clean-blog-node\src\lib\util\seed-db.ts:4:1)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Module.m._compile (C:\Projekte\sb-clean-blog-node\node_modules\ts-node\src\index.ts:814:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Object.require.extensions. [as .ts] (C:\Projekte\sb-clean-blog-node\node_modules\ts-node\src\index.ts:817:12)
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] ts-node: ts-node -r tsconfig-paths/register -r dotenv/config "scripts/db/db-seed.ts"
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] ts-node script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\muell\AppData\Roaming\npm-cache_logs\2020-06-27T19_24_03_739Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] db:seed: npm run ts-node scripts/db/db-seed.ts
npm ERR! Exit status 1
npm ERR!

Already tried to reinstall byrypt, reinstalled all modules but nothing works

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.