Node.js API
Claypot provides a Node.js API which can be used directly in Node.js runtime.
The Node.js API is useful in scenarios in which you need to write models or plugins.
Example
import { cache, logger } from "claypot";
export default class MyModel {
async hello() {
const message = await cache.get("myMessage");
logger.debug(message);
// do sth...
}
}
API Reference
start([opitons])
import { start } from "claypot";
Starting a Claypot server under process monitor.
Arguments
options
(Object): Please checkout configuration
startPure([opitons])
import { start } from "claypot";
Starting a Claypot server without process monitor.
Arguments
options
(Object): Please checkout configuration
stop([options])
import { stop } from "claypot";
Stopping a Claypot server.
Arguments
options
(Object):name
(String): Defining which server you want to stop.force
(Boolean): Force stopping without confirmation.
config Object
import { config } from "claypot";
Get the configuration object. (READ ONLY)
Tips
It useful to use config.production
to detect current environment.
cache Object
import { cache } from "claypot";
Get the default cache store.
A cache store is powered by cache-manager which provides the following methods:
get(key)
: Get a cache value by key.set(key, value, options)
: Get a cache value by key.wrap(key, save, options)
: Get a cache value with a fallback save function.
All of these methods returns a promise.
Please checkout cache-manager for detail.
cacheStores Object
import { cacheStores } from "claypot";
Get all cache stores. Claypot support multi cache stores by defining dbs
configuration.
models Object
import { models } from "claypot";
Get models.
logger Object
import { logger } from "claypot";
Get the default logger.
Claypot provides a powerful log system powered by pot-logger. A logger provides a set of log levels, such as logger.debug()
, logger.info()
, logger.error()
, etc. Please checkout pot-logger for detail.
createLogger(category[, description])
import { createLogger } from "claypot";
Create a custom logger. Please checkout pot-logger for detail.
getLogger(category)
import { getLogger } from "claypot";
Get logger by category. If not found, it would return the default logger. Please checkout pot-logger for detail.
ensureLogger(category[, description])
import { getLogger } from "claypot";
Get logger by category. If not found, create one. Please checkout pot-logger for detail.
setLoggers(keyStringOrConfigObject[, value])
import { setLoggers } from "claypot";
Set loggers. Please checkout pot-logger for detail.
overrideConsole([logger])
import { overrideConsole } from "claypot";
Override native console. Notice that console.log() will be equal with logger.info(). Please checkout pot-logger for detail.
resetConsole()
import { resetConsole } from "claypot";
Reset console to the native one. Only work after overrideConsole() run. Please checkout pot-logger for detail.
overrideConsoleInRuntime(startRun[, logger])
import { overrideConsoleInRuntime } from "claypot";
Override native console in startRun function runtime. Please checkout pot-logger for detail.