Skip to main content
⭐️ If you love EverShop, give it a star on GitHub. Thanks!

Configuration guide

In EverShop, some of the configurations can be done from the admin panel like Payment method, Shipment method, Taxes… We will learn more about these items in our user guide document.

In this section, we will focus on the configuration from the config/ directory. This directory contains the configuration files for the application.

Under the hood, EverShop makes use of config package to handle the configuration.

Configuration file location

Configurations are JSON files stored in configuration files within a directory named ‘config’ located at the root level of your application.

Let’s take a look at an example

{
"shop" : {
"currency": "USD",
"language": "cn",
"weightUnit": "kg"
},
"catalog": {
"product": {
"image": {
"thumbnail": {
"width": 100,
"height": 100
},
"listing": {
"width": 300,
"height": 300
},
"single": {
"width": 500,
"height": 500
},
"placeHolder": "/default/image/placeholder.png"
}
},
"showOutOfStockProduct": false
},
"system": {
"database": {
"host": "localhost",
"port": "5432",
"database": "testrc5again",
"user": "postgres",
"password": "123456"
},
"extensions": [
{
"name": "productComment",
"resolve": "extensions/productComment",
"enabled": true,
"priority": 10
}
]
}
}

Configuration and deployment environment

Configuration files can be overridden and extended by environment variables.

For example, you can overwrite the configuration for your production store by below steps

  • Create a new configuration file named ‘production.json’ in the ‘config’ directory.
  • Add your configuration for production
{
"system": {
"database": {
"host": "aws.production",
"port": "3306",
"database": "production",
"user": "root",
"password": "lsdjgdfhgoiwnm"
}
}
}

Working with configuration in your code

Let's take a look at the below code:

const config = require('config');
//...
const dbConfig = config.get('system.db');
db.connect(dbConfig, ...);

if (config.has('optionalFeature.detail')) {
const detail = config.get('optionalFeature.detail');
//...
}

The above example shows us how to get the configurable variables from the configuration file.

config.get() will throw an exception for undefined keys to help catch typos and missing values. You can use config.has() to test if a configuration value is defined.

You also can use the below method to get the configuration and provide a default value in case the configuration does not exist:

const {
getConfig
} = require('@evershop/evershop/lib/util/getConfig');

let shopTitle = getConfig('shop.language', 'en'),

What goes into a configuration file?

A configuration file is a JSON file that contains the configuration for the application. The configuration file is divided into sections, each section contains a group of configuration items.

The high-level overview of the configuration file can be categorized into:

  • Shop configuration
  • Database configuration
  • Extension configuration
  • Catalog configuration
  • Pricing configuration
  • Theming configuration

Shop configuration

The shop configuration contains the information about the shop. This information is used to display on the storefront.

{
"shop" : {
"currency": "USD",
"language": "cn",
"weightUnit": "kg",
"homeUrl": "http://localhost:3000" // This is the URL to your storefront, it is used for integration with third-party services
}
}

Database configuration

The database configuration contains the connection details of Postgres database

{
"system": {
"database": {
"host": "aws.production",
"port": "3306",
"database": "production",
"user": "root",
"password": "lsdjgdfhgoiwnm"
}
}
}

Extension configuration

The extension configuration contains the list of extensions that are enabled for the application. The extension configuration is used to enable/disable the extension and set the priority for the extension.

{
"system": {
"extensions": [
{
"name": "productComment",
"resolve": "extensions/productComment",
"enabled": true,
"priority": 10
}
]
}
}

Catalog configuration

The catalog configuration contains the configuration for the catalog module. You can configure the image size for the product image, the product listing behavior, and the placeholder image for the product.

{
"catalog": {
"product": {
"image": {
"thumbnail": {
"width": 100,
"height": 100
},
"listing": {
"width": 300,
"height": 300
},
"single": {
"width": 500,
"height": 500
},
"placeHolder": "/default/image/placeholder.png"
}
},
"showOutOfStockProduct": false
}
}

Pricing configuration

The pricing configuration contains the configuration for the pricing calculation. You can configure the rounding behavior and the precision for the pricing calculation.

{
"pricing": {
"rounding": "round",
"precision": 2,
"tax": {
"rounding": "round",
"precision": 2,
"round_level": "unit"
}
}
}

Theming configuration

Theming configuration contains the configuration for the theme. You can configure the logo, favicon, and the meta tag for the storefront.

{
"themeConfig": {
"logo": {
"alt": "You amazing shop logo",
"src": "/logo.png",
"width": 100,
"height": 100
},
"headTags": {
"links": [],
"metas": [],
"scripts": []
},
"copyright": "© 2022 Evershop. All Rights Reserved."
}
}

From the above example, you can see that the logo configuration contains the alt, src, width, and height of the logo. The logo is used to display on the storefront. You can have your logo in the public directory and set the path to the logo in the configuration file.

info

In above example, the logo is located at public/logo.png

Favicon

To add your custom favicon, you can use the themeConfig and add a link tag for the favicon.

{
"themeConfig": {
"headTags": {
"links": [
{
"rel": "icon",
"href": "/favicon.ico"
}
]
}
}
}

You can use this method to add social banners, social icons, and other meta tags to the storefront.

Custom CSS and Javascript

To add your custom CSS and Javascript, you can use the themeConfig and add a script tag for the CSS and JS.

{
"themeConfig": {
"headTags": {
"scripts": [
{
"src": "/custom.js",
"async": true
}
],
"links": [
{
"rel": "stylesheet",
"href": "/custom.css"
}
]
}
}
}