A Node.js starter kit featuring Secuential Asynchrony (async/await), Express (Routing middlewares, Web, Api), Typescript, Mongoose, SCSS, EJS, Nodemon, Bootstrap 4, TSLint.
npm install nodetyped> A Node.js starter kit featuring ES6 with Secuential Asynchrony (async/await),
Express (Routing middlewares, Web, Api),
Typescript,
Mongoose,
MongooseClass,
SCSS,
EJS,
Nodemon,
Bootstrap 4,
TSLint,
Jasmine,
JsDoc,
.
* Simple npm setup and maintenance, without grunt/gulp/webpack/...
* Support for async/await
Example middleware:
``javascript`
async function(req, res, next) {
let title = 'NodeTyped Express';
try {
let data = await readFile(file, 'utf-8'); // no callbacks!
res.render('index', { title: title, dump: data });
} catch (e) {
next(e);
}
}
Example model:
`javascript
@Model({})
export class User extends MongooseModel {
@Column({ type: String, index: true })
name: string;
@Column(Number)
age: number;
static list(): Promise
return this.find().exec();
}
greet() {
return Hello I'm ${this.name};
}
}
`
Make sure you have node version >= 4.0
`bashclone the repo
--depth 1 removes all but one .git commit history
git clone --depth 1 https://github.com/jamg44/NodeTyped.git projectname
If you want to use mongoose models, start mongodb, check localConfig.js and:
`bash
load sample products in database (defaults to 'test')
npm run loadMocks
`
Develop
$3
You can start the server in development mode (linter included) with:
`bash
npm run dev
`Open the browser at:
* http://localhost:3000
Start MongoDB, run 'npm run loadMocks', and check:
* http://localhost:3000/products
* http://localhost:3000/apiv1/products
* http://localhost:3000/apiv1/products/near/(meters)/lon/(lon)/lat/(lat)
As you save in your editor, the compiler will rebuild and restart the server.
$3
Run the linter manually:
`bash
npm run lint
`Clean temp folders:
`bash
npm run clean
`Run the tests:
`bash
npm test
`Generate docs, the output will be in /doc folder:
`bash
npm run doc
`Production / Integration
To run the project in a server you'll want to run the built code instead src version.
`bash
deploy the repo to server and run
npm install
npm start
`Recommendations
* When requiring from _node_modules_ you must use require:
`bash
// require from /node_modules
let express = require('express');
` * With other module types you can use import (node api, created modules):
`bash
import * as fs from 'fs';
import { findConfigFile } from '../lib/utils';
`
* To change project name update package.json
`bash
"name": "project_name", <-----
...
"dev": "tsc && DEBUG=project_name2:* ... <-----
`
* All your reusable functions must return promises for better use with async/await.
`bash
let readFile = function(file, encoding) => {
return new Promise((resolve, reject) => {
fs.readFile(file, encoding, function(err, data) {
if (err) {
return reject(err);
}
resolve(data);
});
});
};
`` * API authentication with JWT
* Add SSL
* Add cluster
* User system (register, login, etc)
* Add sequelize
* Add test coverage report
* Yeoman
* Basic panel
Made with ♡ by Javier Miguel González @javiermiguelg