Skip to content

Node++ switches and constants

Jurek Muszyński edited this page Nov 1, 2022 · 17 revisions

Node++ engine and library use a number of switches and constants, defined as macros in the header files.

Use npp_app.h to turn some of them on, or redefine them:

// Modules & switches

#define NPP_HTTPS           // enable HTTPS
#define NPP_MYSQL           // use MySQL connection
#define NPP_USERS           // enable USERS module

#define NPP_CPP_STRINGS     // allow std::string-s to be used with Node++ functions and macros


// Constants

#define NPP_MIN_USERNAME_LEN  3
#define NPP_MIN_PASSWORD_LEN  8

If not present in npp_app.h, they will have their default values defined in npp.h, npp_lib.h and npp_usr.h (look for configurable).

Modules

Macro Description
NPP_HTTPS Enable HTTPS. Both ports (httpPort & httpsPort) will be open and listened to. OpenSSL, certificate and the key pair are required (see How-to)
NPP_ASYNC Enable multi-process mode (ASYNC)
NPP_MYSQL Open MySQL connection at the start and close it during clean up. Use dbHost, dbPort, dbName, dbUser and dbPassword configuration parameters.
NPP_USERS Enable USERS module. It provides an API for handling all registered users logic, including common things like i.e. password reset. This module also requires NPP_MYSQL.
NPP_ICONV Enable npp_convert(). On Windows, adding iconv library to m.bat is required.
NPP_MULTI_HOST Enable separate resources for different hosts in the same application (see npp_add_host())

Switches and constants

Macro Description Default
NPP_APP_NAME Website name, for example used in OUT_HTML_HEADER macro Node++ Web Application
NPP_APP_DOMAIN Domain name, used in redirections with DOMAINONLY and by the visits counter
NPP_APP_DESCRIPTION If defined, it will be used by OUT_HTML_HEADER macro, in html header
NPP_APP_KEYWORDS If defined, it will be used by OUT_HTML_HEADER macro, in html header
NPP_CPP_STRINGS Allows std::string-s to be used with Node++ functions and macros, example (requires C++17 compatible compiler)
NPP_APP_CUSTOM_MESSAGE_PAGE Render your own message/error page. You also need to define void npp_app_custom_message_page(int ci, int code) in npp_app.cpp.
NPP_ADMIN_EMAIL Admin email used by USERS module
NPP_CONTACT_EMAIL Contact email used by USERS module
NPP_ASYNC_ID Unique integer needed when there's more than one Node++ application using ASYNC on the same machine
NPP_ASYNC_MQ_MAXMSG Max messages in the message queue 10
NPP_ASYNC_REQ_MSG_SIZE Request message size in bytes 8192
NPP_ASYNC_RES_MSG_SIZE Response message size in bytes 8192
NPP_ASYNC_INCLUDE_SESSION_DATA Share application part of the user session (SESSION_DATA) between npp_app and npp_svc
NPP_EMAIL_FROM_NAME Send an email using npp_email() as a specific sender NPP_APP_NAME
NPP_EMAIL_FROM_USER Send an email using npp_email() as a specific user noreply
NPP_EMAIL_FROM_WINDOWS Enable email sending on Windows, see npp_email(https://github.com/rekmus/nodepp/wiki/npp_email) for details
NPP_ALLOW_BEARER_AUTH If ls cookie is not present in request, use Authorization Bearer value
NPP_ENABLE_RELOAD_CONF Enable reloading npp.conf without restart via POST /npp_reload_conf from 127.0.0.1
NPP_JSON_KEY_LEN Maximum JSON field name length 31
NPP_JSON_STR_LEN Maximum JSON string value length 255
NPP_JSON_BUFSIZE Maximum length of JSON string 65568
NPP_JSON_MAX_ELEMS Maximum number of elements in JSON objects 15
NPP_JSON_MAX_LEVELS Maximum number of levels in JSON objects 4
NPP_LOGIN_URI Used for redirection when access to protected resource has been requested, see npp_require_auth() login
NPP_MAX_STATICS Maximum number of static resources 1000
NPP_MIN_USERNAME_LEN Minimum user name length for USERS module 2
NPP_MIN_PASSWORD_LEN Minimum password length for USERS module 5
NPP_SESSID_LEN Session id length used in cookies 15
NPP_BLACKLIST_AUTO_UPDATE Automatically add malicious IPs to the file defined in blockedIPList
NPP_COMPRESS_TRESHOLD Minimum response content size to compress (bytes) 500
NPP_COMPRESS_LEVEL Deflate parameter (see zlib) Z_BEST_SPEED
NPP_CONNECTION_TIMEOUT HTTP connection timeout (seconds) 180
NPP_SESSION_TIMEOUT Anonymous session timeout (seconds) 300
NPP_MYSQL_RECONNECT Open MySQL connection with auto-reconnect option. I recommend not to use this option at the beginning, until you're familiar with MySQL settings, for reconnect happens quietly and without you knowing, this may be impacting your app's performance. See wait_timeout.
NPP_REQUIRED_AUTH_LEVEL Default resource authorization level, see npp_require_auth() AUTH_LEVEL_NONE
NPP_DEFAULT_USER_AUTH_LEVEL Default user authorization level, see npp_require_auth() AUTH_LEVEL_USER
NPP_DOMAIN_ONLY Always redirect to NPP_APP_DOMAIN
NPP_DONT_LOOK_FOR_INDEX By default, when there's a plain GET / request, and res/index.html is present, Node++ serves it. Use this flag to disable this.
NPP_DONT_FLAG_BOTS Disable bots checking (see REQ_BOT)
NPP_DONT_NOTIFY_NEW_USER Disable notifying new user about the new account created with npp_usr_add_user()
NPP_DONT_PASS_QS_ON_LOGIN_REDIRECTION When logged in session is required for the resource and there's no logged in session, request will be redirected to APP_LOGIN_URI. By default the query string is passed as well. Use this switch to disable this.
NPP_DONT_RESCAN_RES By default, Node++ engine rescans res, resmin and snippets directories every 60 seconds, rereading the files when changed. Use this flag to disable this.
NPP_DEBUG Highest level debug output. Use with care, as this may produce quite a huge log files.
NPP_EXPIRES_STATICS Used to calculate response header value for static resources (days from today, updated every midnight). If 0, Expires header for statics will not be sent. 90
NPP_EXPIRES_GENERATED Used to calculate response header value for rendered content (days from today, updated every midnight). If 0, Expires header for generated content will not be sent. 30
NPP_FD_MON_EPOLL Monitor connected sockets using epoll() Default on Linux
NPP_FD_MON_POLL Monitor connected sockets using poll() Default on macOS
NPP_FD_MON_SELECT Monitor connected sockets using select() Default on Windows
NPP_HSTS_INCLUDE_SUBDOMAINS Add includeSubDomains to Strict-Transport-Security response header
NPP_HSTS_MAX_AGE HSTS max-age parameter 31536000
NPP_AUTH_SESSION_TIMEOUT Logged in session caching timeout (seconds) 1800
NPP_MAX_BLACKLIST Blocked IP list size 10000
NPP_MAX_MESSAGES Maximum number of messages 1000
NPP_MAX_STRINGS Maximum number of strings 1000
NPP_MAX_PAYLOAD_SIZE Maximum incoming payload size in bytes 16777216 (16 MB)
MAX_ULA_BEFORE_FIRST_SLOW Maximum unsuccessful login attempts before first slowing down (1 attempt per minute will be allowed) 10
MAX_ULA_BEFORE_SECOND_SLOW Maximum unsuccessful login attempts before second slowing down (1 attempt per hour will be allowed) 25
MAX_ULA_BEFORE_THIRD_SLOW Maximum unsuccessful login attempts before third slowing down (1 attempt per 23 hours will be allowed) 100
MAX_ULA_BEFORE_LOCK Maximum unsuccessful login attempts before locking user out 1000
NPP_MAX_WHITELIST Whitelist size 1000
NPP_MEM_TINY Sets the memory model
NPP_MEM_SMALL Sets the memory model
NPP_MEM_MEDIUM Sets the memory model (default)
NPP_MEM_LARGE Sets the memory model
NPP_MEM_XLARGE Sets the memory model
NPP_MEM_XXLARGE Sets the memory model
NPP_MEM_XXXLARGE Sets the memory model
NPP_MEM_XXXXLARGE Sets the memory model
NPP_MEM_XXXXXLARGE Sets the memory model
NPP_MEM_XXXXXXLARGE Sets the memory model
NPP_MSG_DESCRIPTION_PIPES Make OUT_MSG_DESCRIPTION() to send response pipe-delimited instead of JSON
NPP_NO_HSTS Turn HSTS off
NPP_NO_IDENTITY By default Node++ introduces itself in HTTP headers, with Server: Node++ (server) and User-Agent: Node++ (client via CALL_HTTP). Use this flag to turn it off.
NPP_NO_NOSNIFF By default, there's a X-Content-Type-Options: nosniff header added to a response with content. Use this flag to turn it off.
NPP_NO_SAMEORIGIN By default, there's a X-Frame-Options: SAMEORIGIN header added to a response with content. Use this flag to turn it off.
NPP_OUT_CHECK_REALLOC Sets the OUT() and OUT_BIN() mode. Every write checks available space, resizes if necessary. (default)
NPP_OUT_CHECK Sets the OUT() and OUT_BIN() mode. Every write checks available space, stop writing when exhausted.
NPP_OUT_FAST Sets the OUT() and OUT_BIN() mode. No check, fast and dangerous.
QS_DEF_HTML_ESCAPE Sets the QS mode. HTML-escapes value, i.e. ' will become '. (default)
QS_DEF_SQL_ESCAPE Sets the QS mode. SQL-escapes value, i.e. ' will become \'.
QS_DEF_DONT_ESCAPE Sets the QS mode. Don't escape value.
CALL_HTTP_DONT_CACHE_ADDRINFO By default CALL_HTTP() caches last 100 addresses to avoid unnecessary DNS querying. Use this flag to disable this.
CALL_HTTP_MAX_RESPONSE_LEN CALL_HTTP() maximum response length in bytes 1048576
NPP_PEPPER_01 Users' passwords pepper, part 1. Use random, 4−7 characters long string. abcde
NPP_PEPPER_02 Users' passwords pepper, part 2. Use random, 4−7 characters long string. fghij
NPP_PEPPER_03 Users' passwords pepper, part 3. Use random, 4−7 characters long string. klmno
NPP_PEPPER_04 Users' passwords pepper, part 4. Use random, 4−7 characters long string. pqrst
NPP_PEPPER_05 Users' passwords pepper, part 5. Use random, 4−7 characters long string. uvwxy
NPP_STRINGS_SEP Strings' separator in strings.LL-CC files |
NPP_TMP_BUFSIZE Temporary buffer (used by OUT()) size in bytes OUT_BUFSIZE
NPP_USER_ACTIVATION_HOURS How many hours user has to activate account 24
NPP_USER_KEEP_LOGGED_DAYS ls cookie validity period 30
NPP_USERS_BY_EMAIL Use email to authenticate users. Mutually exclusive with NPP_USERS_BY_LOGIN.
NPP_USERS_BY_LOGIN Use login or email to authenticate users. Mutually exclusive with NPP_USERS_BY_EMAIL (default)
Clone this wiki locally