Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Volodymyr Saakian committed Mar 22, 2020
2 parents 25e84f1 + 3250f4b commit 740ae1c
Show file tree
Hide file tree
Showing 17 changed files with 5,265 additions and 854 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<<<<<<< HEAD
.vscode/
build/
typings/
node_modules/
.DS*
._.*
.idea/
yarn.lock
yarn.lock
#Build folder
build/

#Modules folder
node_modules/

#Logs files
yarn-error.log

36 changes: 6 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
### Modern Express | Easy starter project for writing modern Express MongoDb Applications using TypeScript and Webpack
### Ts Node Server

This project is used to quickly get started with Webpack using Express, MongoDb, Webpack and TypeScript. The intention of this project is to learn to use Webpack with out getting bogged down in the details of configuring Webpack. Below is a list of the outcomes of this project.
Start the dev server "yarn run server:dev:nodemon"
Build application watch "yarn run build"
Compiled start server "yarn run compiled"
Clean all build "yarn run clean"

1. Automates the task of setting up Webpack
2. Cleanly installs and setups Webpack with out polluting the global system scope
3. Creates basic Express project to write TypeScript
4. Cleanly builds TypeScript code into a build directory
5. Stores and Saves Typings for VSCode
6. Uses `ejs` as the templating engine

**Setup**
---
**[Clone this Repository](https://github.com/lossless1/nodets-webpack-starter/archive/master.zip)**

```
yarn install
```

**Run Builds**
---
```
yarn run build
```

**Run Application**
---
```
yarn start
mongod
```
Simple start server "yarn start"
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello worldd');
9 changes: 0 additions & 9 deletions config.json

This file was deleted.

14 changes: 14 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"port": 1337,
"security": {
"tokenLife": 3600
},
"mongodb": {
"protocol":"mongodb",
"host":"localhost",
"port":"27017",
"user":"name",
"db":"test",
"uri": "mongodb://localhost:27017/test"
}
}
25 changes: 25 additions & 0 deletions mongo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var MongoClient = require('mongodb').MongoClient
, assert = require('assert');

// Connection URL
var url = 'mongodb://localhost:27017/myproject';
// Use connect method to connect to the Server
MongoClient.connect(url,{ useNewUrlParser: false } , function(err, db) {
assert.equal(null, err);
console.log("Connected correctly to server");
console.log(db);

// Insert a single document
db.collection('inserts').insertOne({
a:1
, b: function() { return 'hello'; }
}, {
w: 'majority'
, wtimeout: 10000
, serializeFunctions: true
}, function(err, r) {
assert.equal(null, err);
assert.equal(1, r.insertedCount);
db.close();
});
});
16 changes: 16 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"verbose": true,
"ignore": ["*.test.js", "fixtures/*", "**/*.spec.ts"],
"execMap": {
"echo": "1",
"ts": "./node_modules/.bin/ts-node bin/www.ts",
"rb": "ruby",
"pde": "processing --sketch={{pwd}} --run"
},
"watch": [
"**/*"
],
"env": {
"NODE_ENV": "development"
}
}
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
"test": "tests"
},
"scripts": {
"server:dev:nodemon": "NODE_ENV=development nodemon --watch '**/*.ts' --ignore '**/*.spec.ts' --exec 'ts-node' bin/www.ts",
"server:dev:nodemon": "./node_modules/.bin/nodemon bin/www.ts",
"build": "ts-node node_modules/webpack/bin/webpack.js --config config/webpack.config.ts",
"compiled": "ts-node build/compiled",
"clean": "rimraf build",
"start": "yarn run server:dev:nodemon"
},
"nodemonConfig": {
"ignore": [
"test/*",
"docs/*"
],
"delay": "2500",
"NODE_ENV": "development"
},
"main": "",
"keywords": [
"Easy",
Expand Down Expand Up @@ -63,7 +71,7 @@
"@types/nconf": "^0.0.36",
"@types/oauth2orize": "^1.8.3",
"@types/winston": "^2.3.7",
"nodemon": "^1.14.10",
"nodemon": "^1.18.2",
"ts-loader": "^2.0.2",
"ts-node": "^4.1.0",
"typescript": "^2.2.1",
Expand Down
3 changes: 1 addition & 2 deletions src/libs/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as nconf from 'nconf';

nconf.argv().env().file({
file: './config.json'
file: './config/config.json'
})
export { nconf };
9 changes: 4 additions & 5 deletions src/libs/mongoose.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IRefreshTokenModel } from './../models/RefreshToken';
import { IAccessTokenModel, IAccessToken } from './../models/AccessToken';
import { IArticle } from './../models/Article';
import { IRefreshTokenModel } from '../models/RefreshToken';
import { IAccessTokenModel, IAccessToken } from '../models/AccessToken';
import { IArticle } from '../models/Article';
import * as mongoose from 'mongoose';
import log from './winston.error';
import { nconf } from './config';
Expand All @@ -9,7 +9,7 @@ import { Document, Schema, model } from 'mongoose';
import { IClientModel } from '../models/Client';
import { IUserModel } from '../models/User';

mongoose.connect(nconf.get('mongoose:uri'));
mongoose.connect(nconf.get('mongodb:uri'), { useNewUrlParser: true });

let db = mongoose.connection;

Expand Down Expand Up @@ -147,5 +147,4 @@ let RefreshToken: Schema = new Schema({
});

let RefreshTokenModel= model<IRefreshTokenModel>('RefreshToken', RefreshToken);

export { ArticleModel, UserModel, Client, ClientModel, RefreshTokenModel, AccessTokenModel };
29 changes: 29 additions & 0 deletions src/logs/combined.log
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,32 @@
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"level":"error","message":"connection error:"}
{"level":"error","message":"connection error:"}
{"level":"error","message":"connection error:"}
{"level":"error","message":"connection error:"}
{"level":"error","message":"connection error:"}
{"level":"error","message":"connection error:"}
{"level":"error","message":"connection error:"}
{"level":"error","message":"connection error:"}
{"level":"error","message":"connection error:"}
{"level":"error","message":"connection error:"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
{"message":"Connection successfull","level":"info"}
File renamed without changes.
4 changes: 2 additions & 2 deletions src/routes/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Response, Request, Router, NextFunction } from 'express';
import { BaseRoute } from "./route";
import { BaseRoute } from "./base";

export class ErrorRoute extends BaseRoute {
constructor() {
Expand All @@ -17,7 +17,7 @@ export class ErrorRoute extends BaseRoute {
this.title = "Error | Template";

let options: Object = {
"message": "Error 404"
message: "Error 404"
}
this.render(req, res, "error", options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseRoute } from './route';
import { BaseRoute } from './base';
import { Request, NextFunction, Response, Router } from 'express';

export class IndexRoute extends BaseRoute {
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ErrorRoute } from './routes/error';
import { Application, Request, Router, Response, NextFunction } from 'express';
import { IndexRoute } from './routes/index';
import { IndexRoute } from './routes';
import * as express from 'express';
import * as path from 'path';
import * as logger from 'morgan';
Expand Down
Loading

0 comments on commit 740ae1c

Please sign in to comment.