├── .nvmrc ├── src ├── lib │ ├── tools.lib.ts │ ├── index.ts │ └── prisma.lib.ts ├── types │ └── global.d.ts ├── config │ └── global │ │ ├── index.ts │ │ └── global.config.ts ├── services │ └── example │ │ ├── index.ts │ │ └── example.service.ts └── index.ts ├── .gitignore ├── .env-sample ├── prisma └── schema.prisma ├── .eslintrc.js ├── .prettierrc.js ├── tsconfig.json ├── .editorconfig ├── Dockerfile ├── Taskfile.yml ├── README.md └── package.json /.nvmrc: -------------------------------------------------------------------------------- 1 | v14.17.1 -------------------------------------------------------------------------------- /src/lib/tools.lib.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /src/types/global.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | -------------------------------------------------------------------------------- /src/config/global/index.ts: -------------------------------------------------------------------------------- 1 | export * from './global.config' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .history 2 | dist/ 3 | node_modules/ 4 | *.log 5 | .env -------------------------------------------------------------------------------- /src/services/example/index.ts: -------------------------------------------------------------------------------- 1 | export * from './example.service' 2 | -------------------------------------------------------------------------------- /src/lib/index.ts: -------------------------------------------------------------------------------- 1 | export * from './tools.lib' 2 | export * from './prisma.lib' 3 | -------------------------------------------------------------------------------- /src/services/example/example.service.ts: -------------------------------------------------------------------------------- 1 | export function example() { 2 | return { data: 'example' } 3 | } 4 | -------------------------------------------------------------------------------- /.env-sample: -------------------------------------------------------------------------------- 1 | PORT=3005 2 | HOSTNAME=0.0.0.0 3 | DATABASE_URL="postgres://user:pass@localhost:5432/powerstack?sslmode=disable" -------------------------------------------------------------------------------- /src/lib/prisma.lib.ts: -------------------------------------------------------------------------------- 1 | import { PrismaClient } from '@prisma/client' 2 | 3 | export const prisma = new PrismaClient() 4 | -------------------------------------------------------------------------------- /prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | generator client { 2 | provider = "prisma-client-js" 3 | } 4 | 5 | datasource db { 6 | provider = "postgresql" 7 | url = env("DATABASE_URL") 8 | } 9 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: 'standard-with-typescript', 3 | parserOptions: { 4 | project: './tsconfig.json', 5 | }, 6 | rules: { 7 | '@typescript-eslint/explicit-function-return-type': 'off', 8 | 'no-console': 'off', 9 | 'no-use-before-define': 'off', 10 | }, 11 | } 12 | -------------------------------------------------------------------------------- /src/config/global/global.config.ts: -------------------------------------------------------------------------------- 1 | import * as env from 'env-var' 2 | 3 | export interface Config { 4 | hostname: string 5 | port: number 6 | } 7 | 8 | export const config: Config = { 9 | hostname: env.get('HOSTNAME').asString() || '0.0.0.0', 10 | port: env.get('PORT').asIntPositive() || 3000, 11 | } 12 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | // defaults have been commented out 2 | // https://prettier.io/docs/en/options.html 3 | 4 | module.exports = { 5 | tabWidth: 2, 6 | semi: false, 7 | singleQuote: true, 8 | trailingComma: 'all', 9 | printWidth: 100, 10 | importOrder: ['^@(.*)$', '^~/(.*)$', '^[./]'], 11 | importOrderSeparation: true, 12 | importOrderSortSpecifiers: true, 13 | } 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "rootDir": "src", 5 | "target": "es2017", 6 | "lib": ["esnext"], 7 | "declaration": false, 8 | "sourceMap": true, 9 | "module": "commonjs", 10 | "moduleResolution": "node", 11 | "experimentalDecorators": false, 12 | "esModuleInterop": true, 13 | "forceConsistentCasingInFileNames": true 14 | }, 15 | "include": ["src"] 16 | } 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | max_line_length = 130 11 | trim_trailing_whitespace = true 12 | 13 | [{Makefile,makefile,**.mk,*.py}] 14 | # Use tabs for indentation (Makefiles require tabs) 15 | indent_style = tab 16 | 17 | [*.md] 18 | max_line_length = 0 19 | trim_trailing_whitespace = false 20 | 21 | [COMMIT_EDITMSG] 22 | max_line_length = 72 23 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:16 as builder 2 | WORKDIR /usr/src/app 3 | RUN yarn --ignore-optional global add typescript 4 | COPY package.json . 5 | COPY yarn*.lock . 6 | RUN yarn --ignore-optional --frozen-lockfile install 7 | COPY . . 8 | RUN npx prisma generate 9 | RUN yarn build 10 | 11 | # this breaks prisma 12 | # FROM node:14-slim as runtime 13 | # WORKDIR /usr/src/app 14 | # COPY --from=builder /usr/src/app/dist . 15 | # COPY --from=builder /usr/src/app/node_modules ./node_modules 16 | CMD [ "node", "dist/" ] 17 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import * as http from 'http' 2 | 3 | import { config } from './config/global/global.config' 4 | 5 | const indexer = async () => { 6 | console.log('Subscribing to blockchain data ...') 7 | } 8 | 9 | const server = http.createServer((_req, res) => { 10 | res.statusCode = 200 11 | res.setHeader('Content-Type', 'text/plain') 12 | res.end('Service running') 13 | }) 14 | 15 | indexer() 16 | server.listen(config.port, config.hostname, () => 17 | console.log(`Server running at http://${config.hostname}:${config.port}/`), 18 | ) 19 | -------------------------------------------------------------------------------- /Taskfile.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | dotenv: ['.env'] 4 | silent: true 5 | 6 | tasks: 7 | build: 8 | cmds: 9 | - docker build -t powerstack-voyager:local . 10 | 11 | run: 12 | cmds: 13 | - docker run --name powerstack-voyager --env-file .env -p 3307:3307 -d powerstack-voyager:local 14 | 15 | id: 16 | cmds: 17 | - docker ps -aqf "name=^powerstack-voyager$" 18 | 19 | stop: 20 | cmds: 21 | - docker stop powerstack-voyager 22 | 23 | start: 24 | cmds: 25 | - docker start powerstack-voyager 26 | 27 | restart: 28 | cmds: 29 | - docker restart powerstack-voyager 30 | 31 | kill: 32 | cmds: 33 | - docker kill powerstack-voyager 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NodeJS Template 2 | 3 | NodeJS Starter Template 4 | 5 | ## Yarn 6 | 7 | ``` 8 | # Install project dependencies 9 | yarn 10 | 11 | # Development server with reload 12 | yarn dev 13 | 14 | ``` 15 | 16 | ## Docker 17 | 18 | ``` 19 | # Build the image 20 | docker build -t your-image-name:local . 21 | 22 | # Start a container 23 | docker run --name your-image-name --env-file .env -p 3300:3300 -d your-image-name:local 24 | 25 | # Get container ID 26 | docker ps -aqf "name=^image-name-here$" 27 | 28 | # Print app output 29 | docker logs -f your-image-name 30 | 31 | # Stop, start, restart, kill 32 | docker stop your-image-name 33 | docker start your-image-name 34 | docker restart your-image-name 35 | docker kill your-image-name 36 | ``` 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "powerstack-node", 3 | "version": "1.1.0", 4 | "description": "", 5 | "main": "index.js", 6 | "repository": "", 7 | "license": "UNLICENSED", 8 | "scripts": { 9 | "dev": "env-cmd ts-node-dev --no-deps --no-notify --respawn src/index", 10 | "start": "env-cmd node ./dist", 11 | "build": "tsc -b", 12 | "lint": "eslint --ignore-path .gitignore \"**/*.+(js|ts|tsx)\"", 13 | "format": "prettier --ignore-path .gitignore --write \"**/*.+(js|json|ts|tsx)\"", 14 | "prisma-gen": "prisma db pull && prisma generate" 15 | }, 16 | "lint-staged": { 17 | "*.{ts,tsx,js}": [ 18 | "prettier --write", 19 | "eslint --fix" 20 | ] 21 | }, 22 | "husky": { 23 | "hooks": { 24 | "pre-commit": "lint-staged" 25 | } 26 | }, 27 | "devDependencies": { 28 | "@trivago/prettier-plugin-sort-imports": "^4.1.1", 29 | "@types/node": "^18.15.11", 30 | "@typescript-eslint/eslint-plugin": "^5.57.1", 31 | "copyfiles": "^2.4.1", 32 | "env-cmd": "^10.1.0", 33 | "eslint": "^8.35.0", 34 | "eslint-config-prettier": "^8.7.0", 35 | "eslint-config-standard": "^17.0.0", 36 | "eslint-config-standard-with-typescript": "^34.0.0", 37 | "eslint-plugin-import": "^2.27.5", 38 | "eslint-plugin-n": "^15.6.1", 39 | "eslint-plugin-node": "^11.1.0", 40 | "eslint-plugin-prettier": "^4.2.1", 41 | "eslint-plugin-promise": "^6.1.1", 42 | "husky": "^8.0.3", 43 | "lint-staged": "^13.1.2", 44 | "postcss": "^8.4.21", 45 | "prettier": "2.8.4", 46 | "prettier-standard": "^16.4.1", 47 | "prisma": "^4.12.0", 48 | "rimraf": "^4.4.0", 49 | "ts-node-dev": "^2.0.0", 50 | "typescript": "^4.9.5" 51 | }, 52 | "dependencies": { 53 | "@prisma/client": "^4.12.0", 54 | "env-var": "^7.3.0" 55 | } 56 | } 57 | --------------------------------------------------------------------------------