mkdir -p "$NANO_POW_LOGS";
if [ "$1" = '--server' ]; then
shift;
- node "$SCRIPT_DIR"/server.js > "$NANO_POW_LOGS"/nano-pow-server-$(date -u -Iseconds).log 2>&1 & echo "$!" > "$NANO_POW_HOME"/server.pid;
+ node "$SCRIPT_DIR"/server.js >> "$NANO_POW_LOGS"/nano-pow-server-$(date -I).log 2>&1 & echo "$!" > "$NANO_POW_HOME"/server.pid;
sleep 0.1;
if [ "$(ps | grep $(cat $NANO_POW_HOME/server.pid))" = '' ]; then
cat $(ls -td "$NANO_POW_LOGS"/* | head -n1);
* to only output when debug mode is enabled.
*/
function log (...args: any[]): void {
- if (CONFIG.DEBUG) console.log(new Date(Date.now()).toLocaleString(), 'NanoPow', args)
+ if (CONFIG.DEBUG) {
+ const d = new Date(Date.now())
+ const opts: Intl.DateTimeFormatOptions = {
+ hour12: false,
+ dateStyle: 'medium',
+ timeStyle: 'medium'
+ }
+ console.log(d.toLocaleString(navigator.language, opts), `NanoPow[${process.pid}]:`, args)
+ }
}
process.title = 'NanoPow Server'
// Listen on configured port
server.listen(CONFIG.PORT, async (): Promise<void> => {
const { port } = server.address() as AddressInfo
- log(`Server process ${process.pid} listening on port ${port}`)
+ CONFIG.PORT = port
+ log(`Server listening on port ${port}`)
process.send?.({ type: 'listening', port })
})