CodeLighthouse and Node.js — it just makes sense
By: Kyle Mistele
Tags: Nodejs, Microservices, Software Development, Expressjs, Quality Assurance

CodeLighthouse and Node.js — it just makes sense

Node.js is here, and it’s here to stay — both at CodeLighthouse and in the developer world at large. Node.js has absolutely exploded in terms of popularity since 2009. In general, JavaScript remains extremely popular — the 2020 StackOverflow developer survey ranks JavaScript as the #1 most commonly used language, beating contenders like Python, Java, and PHP:

SO’s 2020 Developer Survey — most popular programming, scripting, and markup languages

Node.js is no different — StackOverflow’s data places it as the most popular entry in frameworks, libraries, and tools category by a huge margin:

SO’s 2020 Developer Survey — most popular frameworks, libraries, and tools

As it turns out, the combination of full-stack JavaScript, asynchronous operations, and a rich ecosystem makes for a winning combination. Node.js is used for everything from web apps to RESTful APIs to microservices architectures.

In the past few weeks, the CodeLighthouse team has heard from numerous individuals and companies who said they’d love to see support for Node. We listened to your feedback, and we burned the midnight oil to build this feature, putting it out in less than a week. We’re proud to announce first-class support for Node.js!

Getting Started with the Node.js SDK

Adding our Node.js SDK to your project with NPM couldn’t be easier — simply run npm install codelighthouse (for NPM version 5 or older, make sure to use the -s flag to add it to your package.json ).

Importing and configuring the SDK is similarly easy, but slightly different from our Python SDK:

Your organization_name and api_key can be found in your CodeLighthouse dashboard. If you don’t have a CodeLighthouse account yet, you can sign up for free! More details on the other configuration parameters can be found in our docs.

Once you’ve got the SDK set up, you have a couple of options on how to use it:

The Global Exception Handler

By default, CodeLighthouse will automatically catch all uncaught exceptions and unhandled promise rejections. Application error notifications will be sent to the user specified by the default_email configuration option. The global exception handler can be disabled by passing the keyword argument enable_global_handler=false to the SDK configuration.

It’s important to note that this might not always behave as expected if you’re using frameworks like Express.js since they often implicitly provide their own error handlers. For example, Express will catch exceptions inside of routes and handle them before they reach our global exception handler. Fortunately, we have a solution.

CodeLighthouse’s Express.js Integration

We knew from the start that we wanted to include support for Express.js into our SDK. Its overwhelming popularity made this an easy call. Because of this, we’ve made it easy to report application errors that happen inside your Express app:

Integrating CodeLighthouse into your Express.js app is easy!

Note that all notifications for uncaught exceptions and unhandled promise rejections will be sent to the user specified in the SDK configuration.

Manually Catching Exceptions

Of course, we anticipate that many developers will already be performing exception handling in their code, but may want to send & receive notifications for those handled exceptions anyways. Our SDK provides an easy way for you to do this as well:

As the example demonstrates, you can either send notifications to the default user specified in the SDK, or to another user in your CodeLighthouse organization. You can view and invite additional users to your CodeLighthouse organization on the “users” page in your dashboard.

Still want to know more?

Do you have any questions? Are you looking for tech support, support for another language, or a plan tailored specifically to your organization’s needs? Check out our documentation page, reach out to us at hello@codelighthouse.io or visit our contact page — we’d love to hear from you!