Sign inSign up

woloxinfra/gosmo-rules-api-node

By woloxinfra

•Updated over 7 years ago

Test

Image
0

898

woloxinfra/gosmo-rules-api-node repository overview

⁠ExpressJS Bootstrap Build Status

Kickoff for ExpressJS⁠ applications.

⁠First steps

⁠Installing node

Get the latest version of node from the official website⁠ or using nvm⁠ Nvm approach is preferred.

⁠Getting dependencies

Run npm install or yarn from rootpath of the project.

⁠Database configuration

Before running the app, make sure you have postgresql installed⁠ and a db created, to create it run the following steps inside a psql terminal:

  1. CREATE DATABASE db_project_name;
  2. \c db_project_name
  3. CREATE ROLE "project_name" LOGIN CREATEDB PASSWORD 'project_name';

Then, set in .env some variables:

  • DB_HOST=localhost
  • DB_PORT=5432
  • DB_NAME=db_project_name
  • DB_USERNAME=project_name
  • DB_PASSWORD=project_name
⁠Migrations

To create a migration, run ./node_modules/.bin/sequelize migration:create --name="my-migration-name".

To run them, execute npm run migrations.

⁠Starting your app

Now, to start your app run npm start in the rootpath of the project. Then access your app at localhost:port. The port is logged in the console where you ran the start script.

⁠Development

⁠Environments

By default, the environment will be development, but you can easily change it using the NODE_ENV environmental variable.

⁠Environment variables

Dotenv is used for managing environment variables. They are stored in the /.env file. Take into account that the variables defined in the bashrc are not overrided.

The environment variables should be added to the .env file in the form of NAME=VALUE, as the following example:

DB_HOST=localhost
DB_USER=root
DB_PASS=superpass

Remember not to push nor commit the .env file.

⁠Logging

To log useful information of your program to the console you just need to import the logger located at app/logger. There are two possible types of logging: info and error. You should use them depending on the type of message you want to show.

Here is an example snippet:

const logger = require('/app/logger');
...
if (error) { 
    logger.error('There is an error);
} else {
    logger.info('There is no error);
}
⁠Debugging

As we know, a NodeJS application is not something easy to debug and because of that we've added the --inspect flag to make it simpler. Chrome DevTools will get started when running your app using the start script (npm start), making your debugging easier.

⁠REPL console

We can use a node console with npm run console. There your service objects are exposed as servicename + "Service". Let's suppose that we have a service users which has a function getAll. In your console you can call usersService.getAll() and see the result. Note that this works also with functions that return promises! To exit the console use .exit.

⁠Documentation

Documentation will be served at /docs. Remember using dictum.js⁠ package to automatically generate documentation for your endpoints. Check this link⁠ for further details.

⁠About

This project is maintained by Wolox⁠ and it was written by Wolox⁠.

Wolox

Tag summary

Content type

Image

Digest

Size

321.4 MB

Last updated

over 7 years ago

docker pull woloxinfra/gosmo-rules-api-node:development