Skip to content

Commit 976b096

Browse files
committed
initial project structure
0 parents  commit 976b096

9 files changed

+3849
-0
lines changed

.gitignore

+244
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
2+
# Created by https://www.gitignore.io/api/node,macos,linux,windows,solidity,jetbrains+all
3+
4+
### JetBrains+all ###
5+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
6+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7+
8+
# User-specific stuff:
9+
.idea/**/workspace.xml
10+
.idea/**/tasks.xml
11+
.idea/dictionaries
12+
13+
# Sensitive or high-churn files:
14+
.idea/**/dataSources/
15+
.idea/**/dataSources.ids
16+
.idea/**/dataSources.xml
17+
.idea/**/dataSources.local.xml
18+
.idea/**/sqlDataSources.xml
19+
.idea/**/dynamic.xml
20+
.idea/**/uiDesigner.xml
21+
22+
# Gradle:
23+
.idea/**/gradle.xml
24+
.idea/**/libraries
25+
26+
# CMake
27+
cmake-build-debug/
28+
29+
# Mongo Explorer plugin:
30+
.idea/**/mongoSettings.xml
31+
32+
## File-based project format:
33+
*.iws
34+
35+
## Plugin-specific files:
36+
37+
# IntelliJ
38+
/out/
39+
40+
# mpeltonen/sbt-idea plugin
41+
.idea_modules/
42+
43+
# JIRA plugin
44+
atlassian-ide-plugin.xml
45+
46+
# Cursive Clojure plugin
47+
.idea/replstate.xml
48+
49+
# Ruby plugin and RubyMine
50+
/.rakeTasks
51+
52+
# Crashlytics plugin (for Android Studio and IntelliJ)
53+
com_crashlytics_export_strings.xml
54+
crashlytics.properties
55+
crashlytics-build.properties
56+
fabric.properties
57+
58+
### JetBrains+all Patch ###
59+
# Ignores the whole .idea folder and all .iml files
60+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
61+
62+
.idea/
63+
64+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
65+
66+
*.iml
67+
modules.xml
68+
.idea/misc.xml
69+
*.ipr
70+
71+
### Linux ###
72+
*~
73+
74+
# temporary files which can be created if a process still has a handle open of a deleted file
75+
.fuse_hidden*
76+
77+
# KDE directory preferences
78+
.directory
79+
80+
# Linux trash folder which might appear on any partition or disk
81+
.Trash-*
82+
83+
# .nfs files are created when an open file is removed but is still being accessed
84+
.nfs*
85+
86+
### macOS ###
87+
*.DS_Store
88+
.AppleDouble
89+
.LSOverride
90+
91+
# Icon must end with two \r
92+
Icon
93+
94+
# Thumbnails
95+
._*
96+
97+
# Files that might appear in the root of a volume
98+
.DocumentRevisions-V100
99+
.fseventsd
100+
.Spotlight-V100
101+
.TemporaryItems
102+
.Trashes
103+
.VolumeIcon.icns
104+
.com.apple.timemachine.donotpresent
105+
106+
# Directories potentially created on remote AFP share
107+
.AppleDB
108+
.AppleDesktop
109+
Network Trash Folder
110+
Temporary Items
111+
.apdisk
112+
113+
### Node ###
114+
# Logs
115+
logs
116+
*.log
117+
npm-debug.log*
118+
yarn-debug.log*
119+
yarn-error.log*
120+
121+
# Runtime data
122+
pids
123+
*.pid
124+
*.seed
125+
*.pid.lock
126+
127+
# Directory for instrumented libs generated by jscoverage/JSCover
128+
lib-cov
129+
130+
# Coverage directory used by tools like istanbul
131+
coverage
132+
133+
# nyc test coverage
134+
.nyc_output
135+
136+
#test-results
137+
test-results
138+
139+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
140+
.grunt
141+
142+
# Bower dependency directory (https://bower.io/)
143+
bower_components
144+
145+
# node-waf configuration
146+
.lock-wscript
147+
148+
# Compiled binary addons (http://nodejs.org/api/addons.html)
149+
build/Release
150+
151+
# Dependency directories
152+
node_modules/
153+
jspm_packages/
154+
155+
# Typescript v1 declaration files
156+
typings/
157+
158+
# Optional npm cache directory
159+
.npm
160+
161+
# Optional eslint cache
162+
.eslintcache
163+
164+
# Optional REPL history
165+
.node_repl_history
166+
167+
# Output of 'npm pack'
168+
*.tgz
169+
170+
# Yarn Integrity file
171+
.yarn-integrity
172+
173+
# dotenv environment variables file
174+
.env
175+
176+
177+
### Solidity ###
178+
# Logs
179+
180+
# Runtime data
181+
182+
# Directory for instrumented libs generated by jscoverage/JSCover
183+
184+
# Coverage directory used by tools like istanbul
185+
186+
# nyc test coverage
187+
188+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
189+
190+
# Bower dependency directory (https://bower.io/)
191+
192+
# node-waf configuration
193+
194+
# Compiled binary addons (http://nodejs.org/api/addons.html)
195+
196+
# Dependency directories
197+
198+
# Typescript v1 declaration files
199+
200+
# Optional npm cache directory
201+
202+
# Optional eslint cache
203+
204+
# Optional REPL history
205+
206+
# Output of 'npm pack'
207+
208+
# Yarn Integrity file
209+
210+
# dotenv environment variables file
211+
212+
installed_contracts
213+
build
214+
215+
### Windows ###
216+
# Windows thumbnail cache files
217+
Thumbs.db
218+
ehthumbs.db
219+
ehthumbs_vista.db
220+
221+
# Folder config file
222+
Desktop.ini
223+
224+
# Recycle Bin used on file shares
225+
$RECYCLE.BIN/
226+
227+
# Windows Installer files
228+
*.cab
229+
*.msi
230+
*.msm
231+
*.msp
232+
233+
# Windows shortcuts
234+
*.lnk
235+
236+
#build
237+
dist
238+
239+
src/**/*.js
240+
src/**/*.js.map
241+
test/**/*.js
242+
test/**/*.js.map
243+
244+
# End of https://www.gitignore.io/api/node,macos,linux,windows,solidity,jetbrains+all

nodemon.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ignore": ["test", ".git", "node_modules"],
3+
"watch": ["src"],
4+
"exec": "npm start",
5+
"ext": "ts"
6+
}

package.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "nodejs-ts-starter",
3+
"description": "Starter project for developing with NodeJs (Typescript) as backend server",
4+
"version": "1.0.0",
5+
"contributors": [
6+
"Marin Petrunić <marin@nodefactory.io>",
7+
"Belma gutlić <belma@nodefactory.io"
8+
],
9+
"license": "UNLICENSED",
10+
"scripts": {
11+
"init": "mkdir dist",
12+
"clean": "rm -rf dist",
13+
"revert": "sequelize --config sequelizecli.js db:migrate:undo",
14+
"revert-all": "sequelize --config sequelizecli.js db:migrate:undo:all",
15+
"migrate": "sequelize --config sequelizecli.js db:migrate",
16+
"prebuild": "npm run clean && npm run init",
17+
"build": "tsc --outDir dist",
18+
"compile": "tsc",
19+
"pretest": "npm run compile && npm run lint",
20+
"test": "tape \"test/**/*.js\" | tap-spec",
21+
"lint": "tslint src/**/*.ts",
22+
"start": "npm run compile && node --inspect=0.0.0.0:56745 -r dotenv/config src/index.js",
23+
"dev": "./node_modules/nodemon/bin/nodemon.js"
24+
},
25+
"dependencies": {
26+
"body-parser": "^1.18.3",
27+
"express": "^4.16.3",
28+
"express-async-errors": "^3.0.0",
29+
"express-validation": "^1.0.2",
30+
"joi": "^13.5.2",
31+
"morgan": "^1.9.0",
32+
"nodemon": "^1.17.4",
33+
"sequelize": "^4.38.0",
34+
"umzug": "^2.1.0",
35+
"winston": "^2.4.4"
36+
},
37+
"devDependencies": {
38+
"@types/express": "^4.16.0",
39+
"@types/tape": "^4.2.32",
40+
"dotenv": "^5.0.1",
41+
"nyc": "^12.0.2",
42+
"runjs": "^4.3.2",
43+
"sequelize-cli": "^4.0.0",
44+
"tap-spec": "^5.0.0",
45+
"tape": "^4.9.1",
46+
"tslint": "^5.11.0",
47+
"typescript": "^3.0.1",
48+
"typescript-eslint-parser": "^18.0.0"
49+
}
50+
}

runfile.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { run, help } = require('runjs');
2+
3+
function clean() {
4+
run('rm -rf node_modules');
5+
run('rm -rf build');
6+
}
7+
8+
function lint() {
9+
run('docker-compose run --rm backend npm run lint');
10+
}
11+
12+
function npm(task = '--help') {
13+
run('docker-compose run --rm backend npm run ' + task);
14+
}
15+
16+
function compile() {
17+
run('docker-compose run --rm backend npm run build');
18+
}
19+
20+
function build() {
21+
run('docker-compose down');
22+
run('docker-compose -f docker-compose-cleanup.yml down -v');
23+
run('docker-compose build');
24+
}
25+
26+
function test() {
27+
run('docker-compose run -e NODE_ENV=test --rm backend npm run test');
28+
}
29+
30+
function dev() {
31+
run('docker-compose up');
32+
}
33+
34+
help(test, 'Runs nodejs tests');
35+
help(dev, 'Starts application and all dependent services');
36+
help(npm, 'Executes npm script');
37+
help(compile, 'Transpiles files to es5');
38+
help(clean, 'Removes all build directories and dependencies');
39+
help(lint, 'Runs eslint on current project');
40+
help(build, 'Builds new docker image');
41+
42+
module.exports = {
43+
clean,
44+
lint,
45+
npm,
46+
build,
47+
test,
48+
compile,
49+
dev,
50+
};

src/App.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as express from "express";
2+
3+
class App {
4+
5+
public server;
6+
7+
constructor() {
8+
this.server = express();
9+
this.addRoutes();
10+
}
11+
12+
private addRoutes(): void {
13+
const router = express.Router();
14+
router.get("/", (req, res) => {
15+
return res.json({
16+
message: "Welcome stranger!",
17+
});
18+
});
19+
this.server.use("/", router);
20+
}
21+
}
22+
23+
export default new App().server;

src/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as winston from "winston";
2+
import app from "./App";
3+
4+
const port = process.env.SERVER_PORT || 3000;
5+
6+
app.listen(port, (err) => {
7+
if (err) {
8+
return winston.error(err);
9+
}
10+
11+
return winston.info(`Server is listening on ${port}`);
12+
});

0 commit comments

Comments
 (0)