Skip to content

Repository files navigation

Node Backend example

Run and Debug app

Prerequisites

  • create .env file with SECRET_KEY in root directory
  • create ormconfig.json file with db connection details (including db password) in root directory

Run app

  • npm install
  • (start mysql server) --> changed to sqlite
  • npm start ... to start nodemon
  • http://localhost:8000/
  • Seeing Database: npm run roles:seed

In case of errors

  • npm install -g nodemon
  • npm install -g ts-node
  • Set-ExecutionPolicy RemoteSigned -Scope CurrentUserke

Debug app

  • NO npm start, just F5 (using Launch via NPM launch.json configuration) OR
  • ctrl + shift + p -> Debug: Toggle Auto Attach Always + npm start

Setup

First steps

  • npm init -y
  • npm i -D typescript ts-node nodemon and TS global npm i -g typescript
  • tsc --init

Configure nodemon

  • create nodemon.json and add stuff

Packages

Express

  • REST API framework
  • npm i express cors
  • Install respective types npm i -D @types/express @types/cors

Further resources

Bcryptjs

  • Encryption package
  • npm i bcryptjs
  • npm i -D @types/bcrypt

TypeORM

SQLite Database

Express-Validation

  • validation library

JWT

  • json web token packages
  • npm i jsonwebtoken
  • npm i -D @types/jsonwebtoken
  • Steps:
    • define payload & create token respectively
    • store token in http-only-cookie
  • npm i cookie-parser ... to receive cookie from api-response
  • npm i -D @types/cookie-parser

environment variables

File Upload - Multer

  • npm i multer
  • npm i -D @types/multer

Export CSV

  • npm i json2csv
  • npm i -D @types/json2csv

TODO

Deployment

Logging


SQL stuff

SQLite

  • Delete all rows and ignore Foreign Keys

    PRAGMA foreign_keys = OFF; DELETE FROM table_name; PRAGMA foreign_keys = ON;

MySql

  • Delete all rows and ignore Foreign Keys

    SET FOREIGN_KEY_CHECKS = 0; truncate table table_name; SET FOREIGN_KEY_CHECKS = 1;


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages