Skip to content
This repository was archived by the owner on Jan 20, 2020. It is now read-only.

Commit 7c952ab

Browse files
author
Luciano Nooijen
committed
Improved folder structure
1 parent dd6c887 commit 7c952ab

25 files changed

+101
-11
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ to start using the package, create a new instance of the NodeBlog class
4444

4545
```js
4646
const nodeBlogConfig = {
47+
client: 'YOUR_DB_CLIENT' // for more info, see https://knexjs.org/
4748
host: 'YOUR_DB_HOST'
4849
database: 'YOUR_DB_NAME'
4950
user: 'YOUR_DB_USER'
5051
pass: 'YOUR_DB_PASS'
52+
debug: true || false
5153
};
5254
const nodeBlog = new NodeBlog(nodeBlogConfig);
5355
```
@@ -80,8 +82,27 @@ For development, the following commands are available:
8082
| `yarn run migrate` | Migrates your database (normal one, not test database) to the most recent migration, seeds will not be ran |
8183
| `yarn run reinstall` | Deletes the `node_modules/` folder and reinstalls everything, if you get some stange dependency errors, run this command |
8284

85+
### Folder structure
86+
87+
```md
88+
├── controllers Controller logic for the module based API
89+
├── database All database related files
90+
│   ├── migrations
91+
│   └── seeds
92+
├── helpers Helper files, for example: logger, database instance
93+
├── server Server configuration
94+
│   ├── controllers
95+
│   ├── middleware
96+
│   │   └── modules
97+
│   └── routes
98+
└── tests All tests written
99+
├── config
100+
└── database
101+
```
102+
83103
# Todo
84104

105+
* Add Yarn seed command
85106
* Add authentication, password hashing -> also improve seed scripts
86107
* Add auth routes to get JWT
87108
* Using https://thejackalofjavascript.com/architecting-a-restful-node-js-app/
@@ -92,6 +113,7 @@ For development, the following commands are available:
92113
* Make sure the application is available both as a NPM module and as a standalone service
93114
* Integrate https://github.com/semantic-release/semantic-release
94115
* Split up standalone and module
116+
* Add XML feed
95117

96118
## Notes
97119

controllers/controllers.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/* eslint-disable global-require */
1+
const Authors = require('./authors');
2+
const Users = require('./users');
3+
// const Categories = require('./categories');
4+
// const Posts = require('./posts');
25

36
module.exports = {
4-
Status: require('./status-controller'),
5-
Authors: require('./authors-controller'),
6-
Users: require('./users-controller'),
7-
Categories: require('./categories-controller'),
8-
Posts: require('./posts-controller'),
7+
Authors,
8+
Users,
99
};
File renamed without changes.

knexfile-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ module.exports = {
2626
},
2727
migrations: {
2828
tableName: 'knex_migrations',
29+
directory: './database/migrations',
2930
},
3031
debug,
3132
asyncStackTraces: debug,
33+
seeds: {
34+
directory: './database/seeds',
35+
},
3236
};

knexfile.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: Improve file: https://knexjs.org/#knexfile, move file to ./database
2+
13
require('dotenv').config();
24

35
// eslint-disable-next-line
@@ -26,7 +28,11 @@ module.exports = {
2628
},
2729
migrations: {
2830
tableName: 'knex_migrations',
31+
directory: './database/migrations',
2932
},
3033
debug,
3134
asyncStackTraces: debug,
35+
seeds: {
36+
directory: './database/seeds',
37+
},
3238
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"node": ">=8.0.0"
2626
},
2727
"scripts": {
28-
"dev": "nodemon",
29-
"start": "node server.js",
28+
"dev": "nodemon server/server.js",
29+
"start": "node server/server.js",
3030
"lint": "eslint --ext .jsx,.js,.ts .",
3131
"test": "NODE_ENV=TEST jest -i",
3232
"test:watch": "NODE_ENV=TEST jest -i --watch",
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { listAuthors } = require('./authors');
1+
const { listAuthors } = require('../../controllers/authors');
22

33
const list = async (req, res) => {
44
const authors = await listAuthors();

0 commit comments

Comments
 (0)