Node Hapi Seed is a Node.js project template which includes standard web project features such build automation, routes, unit testing, Dockerbuild file, configuration, and logging.
git clone https://github.com/ottogiron/node-hapi-seed.git <my-project-name>
git remote set-url origin <my-own-github-repository>
Dev env
Uses nodemon gulp task
cd <my-project-name>
npm -g gulp
npm install
gulp serve
Production/Other
Runs server.js
npm install
npm start
The project template uses Hapi Lab. Check the test folder
Runing tests
npm test
Routes are Hapi.js plugins. All the plugins under routes will be automatically loaded using hapi-plugins-loader.
var Hoek = require('hoek');
exports.register = function (server, options, next) {
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply({ message: 'Welcome to the plot device.' });
}
});
next();
};
exports.register.attributes = {
name: 'api'
};
When running your server in dev enviroment (gulp serve), the project will try to load an .env file using Dotenv module
You should have an .env file in the root of your project which will contain configuration variables that change across enviroments such, resource handles, services, data bases etc. Variables will be attached to process.env as normally happens with enviroment variables.
note: If you don't create an .env file when using gulp serve in your root directory you will see an error.
example .env file
APP_PORT=8080
DB_HOST=localhost
DB_USER=root
DB_PASS=s1mpl3
Contains the application configuration for the server(s).
Contains the application general configuration. If your configuration changes across enviroments you should use an enviroment variable in this file.
Initializes Hapi Glue which eventually will run the configured server(s).
Starts configured servers using Glue.
The project template uses Gulp for build automation. You can define tasks under the build/tasks folder, then you can run them from the command line e.g
gulp serve
Contains a Dockerfile to create a docker image from the project. You can edit the file if you need additional dependencies.
Generating the docker image
docker build -f docker/Dockerfile -t ottogiron/hapiseed .
you can use your own image tag in this case I'm using "ottogiron/hapiseed".
Running a container example
export APP_PORT=8000
docker run --rm -p ${APP_PORT}:${APP_PORT} -e APP_PORT=${APP_PORT} ottogiron/hapiseed
TODO
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Otto Giron
MIT