GithubHelp home page GithubHelp logo

camesine / typescript-restful-starter Goto Github PK

View Code? Open in Web Editor NEW
110.0 5.0 32.0 688 KB

Node.js + ExpressJS + Joi + Typeorm + Typescript + JWT + ES2015 + Clustering + Tslint + Mocha + Chai

License: MIT License

TypeScript 96.27% Dockerfile 1.69% Shell 2.05%
nodejs expressjs sequelize typescript tslint jwt es2015 clustering commonjs rest-api

typescript-restful-starter's Introduction

Typescript-restful-starter

Node.js + ExpressJS + TypeOrm + Typescript + JWT + ES2015 + Clustering + Tslint + Mocha + Chai + Supertest

What use is this Starter App?

  • JWT for protecting routes.
  • Clustering mode for loading many forks depending of the CPU's units.
  • Typeorm for ORM.
  • ES2015 the lastest javascript version has promises and async/await
  • Mocha - Chai for testing
  • Supertest to load the entire server into the tests seamlessly

Structure

/app
	/controllers (Controllers of the app)
	/middlewares (Middlewares for the routes of the app)
	/routes (Routes for Controllers of the app)
	/service (Services for using in any Controller)
	/entity (Models configuration for use)
	/repository (Custom queries)
/config
	/Router.ts (Config file for Routing)
	/Database (DB configuration for use)
	/Server.ts (Server configuration)
config.ts (Config file for the app)
tsconfig.json (File configuration typescript)
tslint.json (File configuration rules typescript)
Index.ts (Main file to start the app)

Install

  1. First clone this repository.

     [email protected]:camesine/Typescript-restful-starter.git
    
  2. Download all dependencies.

     npm install
    
  3. Edit the file ./env and add config database like:

#
# APPLICATION
#
APP_NAME=restful-starter-server
APP_SCHEMA=http
APP_HOST=localhost
APP_PORT=3000

APP_SECRET=HltH3R3


#
# MySQL DATABASE
#
# mysql or mariadb
TYPEORM_CONNECTION=mariadb
TYPEORM_HOST=localhost
TYPEORM_PORT=3306
TYPEORM_USERNAME=root
TYPEORM_PASSWORD=root
TYPEORM_DATABASE=test
TYPEORM_SYNCHRONIZE=true
TYPEORM_LOGGING=error
TYPEORM_LOGGER=advanced-console

#
# PATH STRUCTRUE
#
TYPEORM_ENTITIES=app/models/**/*.ts
TYPEORM_ENTITIES_DIR=app/models

Start App

When execute any of this commands the app start with clustering, creating many cluster apps depending of the numbers of CPU's your computer had.

Development: In Development mode, the express app is started with nodemon for automatic refresh when changes are made.

npm run dev

Test: Run test in development environment

npm test

Production: Run app in production environment

npm start

typescript-restful-starter's People

Contributors

bertyhell avatar camesine avatar krynv avatar mandreko avatar paul75 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  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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

typescript-restful-starter's Issues

Production not works

When I got prod mode, it failed. :

-------------------> RUN PRODUCTION ENVIRONMENT

(node:37129) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token import
(node:37129) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:37133) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token import
(node:37133) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:37132) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token import
(node:37132) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:37137) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token import
(node:37137) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:37136) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token import
(node:37136) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:37131) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token import
(node:37131) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:37135) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token import
(node:37135) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:37130) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token import
(node:37130) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:37134) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token import
(node:37134) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Thanks

Debug using Devtools for Node

Is it possible to add support for debugging with the 'npm run dev' command?
I can't see to make it work using --inspect or --inspect -r ts-node/register Index.ts.

Maybe it's some issue with the combination of nodemon and ts-node.
Debugging support make it so easy to debug issues.

Question : use middlewares

Hello,

If I understand you use maddlewarein routes ? that means that middlesware for exemple for route Users it works for all (get, post, put,...) ?

And If I want to do for all without one ? exemple I want to restrict access JWT for method post, put, delete but not only for Get ? When I can done ?

Thanks

upload image

I'm having trouble uploading photos. Can you guide me on how to do it?

build with ts file orm Typeorm

In your sample you sur for exemple Sample in config :

entities: [
  Sample
],

But me Whencan I use like :

entities: [
  "app/entity/**/*.ts"
],
migrations: [
  "app/migration/**/*.ts"
],
subscribers: [
  "app/subscriber/**/*.ts"
],

When I build it have not in js file but ts in the build folder config.

Thanks

bug launch in the last relase

Hello,

When take last version (clone) and do npm run dev I've got :

if (!options || !options.secret) throw new Error('secret should be set');
                                         ^
Error: secret should be set

Thanks

Using with pm2 ?

Hello,

It is simple to execute the project with PM2 Manager ?

Thanks

add support loaders

Hello,

I want to add crons to applications. And in anothers programs in github I see that doing loaders to load scripts to load. Ans in the loaders I can add crons and do script automatically.

When can I do ?

failed to reload after change mofification

Hello,

When I start 'npm run dev', it works but if I modify a script it want to reload but crash :

...
Error: bind EADDRINUSE null:3000
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at listenOnMasterHandle (net.js:1411:16)
    at rr (internal/cluster/child.js:111:12)
    at Worker.send (internal/cluster/child.js:78:7)
    at process.onInternalMessage (internal/cluster/utils.js:42:8)
    at emitTwo (events.js:131:20)
    at process.emit (events.js:214:7)
    at process.emit (/Users/far-paul/Sites/GOMPOST/server2/node_modules/source-map-support/source-map-support.js:453:21)
    at emit (internal/child_process.js:772:12)
Worker 63493 died with code: 1, and signal: null
Starting a new worker
Error: bind EADDRINUSE null:3000
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at listenOnMasterHandle (net.js:1411:16)
    at rr (internal/cluster/child.js:111:12)
    at Worker.send (internal/cluster/child.js:78:7)
    at process.onInternalMessage (internal/cluster/utils.js:42:8)
    at emitTwo (events.js:131:20)
    at process.emit (events.js:214:7)
    at process.emit (/Users/far-paul/Sites/GOMPOST/server2/node_modules/source-map-support/source-map-support.js:453:21)
    at emit (internal/child_process.js:772:12)
Worker 63492 died with code: 1, and signal: null
Starting a new worker
Error: bind EADDRINUSE null:3000
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at listenOnMasterHandle (net.js:1411:16)
    at rr (internal/cluster/child.js:111:12)
    at Worker.send (internal/cluster/child.js:78:7)
    at process.onInternalMessage (internal/cluster/utils.js:42:8)
    at emitTwo (events.js:131:20)
    at process.emit (events.js:214:7)
    at process.emit (/Users/far-paul/Sites/GOMPOST/server2/node_modules/source-map-support/source-map-support.js:453:21)
    at emit (internal/child_process.js:772:12)
Worker 63494 died with code: 1, and signal: null
Starting a new worker
...

And it not stop I must kill process ....

Thanks for help.

error in launch

Hello,

When I do a npm start it say :

Index.ts(24,11): error TS2322: Type 'string | number' is not assignable to type 'number'.
  Type 'string' is not assignable to type 'number'.
config/Database.ts(5,44): error TS2345: Argument of type '{ type: string; host: string; port: number; username: string; password: string; database:string;...' is not assignable to parameter of type 'ConnectionOptions'.
  Type '{ type: string; host: string; port: number; username: string; password: string; database: string;...' is not assignable to type 'SqljsConnectionOptions'.
    Types of property 'type' are incompatible.
      Type 'string' is not assignable to type '"sqljs"'.

Thanks

Routes not works

I test to launch without modifications and all routes not found, got error 404 ....

Thanks

Tests using SuperTest so server doesn't have to run

Currently, it appears that the server has to be running for the tests to pass. It'd be nice to see it use SuperTest, utilizing the express.app object. This would make it nicer for CI/CD systems to automate testing.

In consol errors

Hello,

When I start I got :

(node:17512) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
(node:17512) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:11268) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
(node:11268) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:23632) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
(node:23632) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:20184) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
(node:20184) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:10800) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
(node:10800) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The errors in console are normal (I have not configure BDD yet) ?

in start 4 message that server started ....

Hello,

When I start it say :

Server is running in process 14136 listening on PORT 3000

Server is running in process 20680 listening on PORT 3000

Server is running in process 7992 listening on PORT 3000

Server is running in process 12616 listening on PORT 3000

Why I have a 4 lines ?

Thanks

in dev run error NODE_ENV

Hello,

Yes it's me again ....

I like your program.

Now In linux or MAC it works but in windows it failed try npm run dev...

I've got :

'NODE_ENV' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.

Thanks

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.