- console
- mongodb
const logging = require("./lib/logging");
//using mongodb as storage
let loggingService = logging.createService({
transport: "mongodb",
mongodb: {
host: "localhost",
port: "27017",
username: "test",
password: "test",
dbname: "nodejs",
collection: "logs",
},
})
OR you can use direct url for mongodb connection
let loggingService = logging.createService({
transport: "mongodb",
mongodb: {
url: "mongodb+srv://username:[email protected]/"
dbname: "nodejs",
collection: "logs",
},
})
//using console as output
let loggingService = logging.createService({
transport: "console",
})
loggingService.write({
severity: "normal",
date_time: new Date().toISOString(),
log_text: "hello world",
attributes: {meta1: "meta1",meta2: "meta2"}
});
- mailgun
- sendgrid
const email = require("./lib/email");
//using mailgun as transport
let emailService = email.createService({
transport: "mailgun",
mailgun:{
username: "your_mailgun_username",
key: "your_mailgun_api_key",
domain: "your_mailgun_verified_domain",
}
});
//using sendgrid as transport
let emailService = email.createService({
transport: "sendgrid",
sendgrid:{
key: "your_sendgrid_api_key",
}
});
emailService.send({
from: "[email protected]",
to: "[email protected]",
subject: "Subject of your email",
body: "body of your html (can contain html)",
});
- twilio
const sms = require("./lib/sms");
//using twilio as transport
let smsService = sms.createService({
transport: "twilio",
twilio: {
accound_sid: "your_twilio_account_sid",
auth_token: "your_twilio_auth_token",
},
});
smsService.send({
from: "+1234567",
to: "+00000000",
body: "Hello world!"
});
- memory
- file
const cache = require("./lib/cache");
//using memory as transport
let cacheService = cache.createService({
transport: "memory",
});
cacheService.put({
key: "hello",
value: "world"
});
cacheService.get({
key: "hello",
});
cacheService.remove({
key: "hello",
});
To enable any service to run over http exposing respective endpoints http configuration element can be passed when creating service.
let loggingService = logging.createService({
transport: "console",
http: {
enabled: true,
port: 1001
}
})
Any service that is passed this http configuration will run on port 1001 exposing its endpoints
POST /write
{"severity":"normal","log_text": "Hello world","date_time":"2023-11-11 01:30:00","attributes":{"meta1":"meta1 value","meta2":"meta2 value"}}
POST /send
{"to":"[email protected]","subject": "This is email subject","body":"this is email body"}
POST /send
{"to":"+0000000","body":"this is sms body"}
To enable any service to listen for a queue or send message to a queue on broker, queue configuration element can be passed when creating service.
let loggingService = logging.createService({
transport: "console",
queue: {
enabled: true,
name: "logs", //name of the queue to listen
}
})
let loggingService = logging.createService({
transport: "console",
queue: {
enabled: true,
name: "logs", //name of the queue to listen
receiver: false, //this will tell the service not to listen for messages from the queue
}
})