Achieving Efficiency and Effectiveness in NodeJs/Full Stack Development

Gary Seymour
8 min readJan 6, 2023

--

These Best Practice articles look at how to deliver efficient, effective and secure applications using NodeJs, Full Stack Development. This series pulls together a number of guides, notes, ideas and industry best practice that we have used through out the years. Its designed to be easy to consume, and right for leaders, business owners and non-technical product owners ( where possible! ) to drive, lead and deliver Best Practice. In this article, we look at how to drive team and output efficiency.

Introduction

Full Stack Development, with NodeJS/Javascript at the core is great platform and base to build advanced maintainable services. This is because

  • Development Efficiency: Full stack JavaScript Developers can work on a web app entirely in that programming language, making it easier for anyone in the team to understand what’s going on.
  • Code Reuse: Since both the backend and frontend use JavaScript, you can reuse chunks of code that follow similar logic and implementation. Applications can be written in one language for both server-side and client-side execution environments.
  • High Performance: Thanks to Node.js, full stack JavaScript developers can take full advantage of non-blocking programming and create fully asynchronous apps.
  • Open Source: Virtually the entire MEAN (MongoDB, Express.js, AngularJS and Node.js) stack is open source.
  • Skills & Resources: According to a recent survey, JavaScript is the most-used technology with over 2/3rd’s of respondents saying they use it in some way.
  • Plenty Of Resources: Incredible support, with tools, frameworks, and libraries readily available for developers, with one of the most thriving communities in the development world.

Like all similar technologies/frameworks, developing solutions efficiently and effectively ( ie keeping costs under control, risks managed and deliveries on time) still requires a focus on process, quality and standards. Businesses look for predictability, and agility ( both in project delivery and business ability to meet ts goals ). Outlined below are some of the key Best Practices methods and approaches that each and every NodeJs project should consider and adopt if it wants to meet those business goals : Version Control, Common Coding Standards, Application Structure, Testing, Monitor Performance, Security, Syntax & Linting, Optimise, Logging and CD/CI.

All should be adopted, adapted, agreed and built into each project life-cycle, owned by the project leadership, and then managed through execution by the product and project managers.

1. Version Control:

Version control remains the key / number one best practices for software development, Using version control ensures collaboration on a project, with tracked/audited change management, recovery, centralised backup and cross team visibility. Git based ( including Github, Gitlb, GitOps ) software engineering has become the norm in cloud based, distributed development, but CVS, SVN and VSTS are all still in common use. “GitOps” has become the backbone of the DevOps and CD/CI revolution, with automatic build, test and deployment across environments part of the drive to efficient delivery, and key to meeting the Agile Manifesto.

2. Common Coding Standards:

Sticking to common standards when developing a Node.js application will help ensure that the code is consistent and easy to read for everyone in the team. Javascript and Nodejs have several style guides and coding standards that developers can adopt to in order to maintain a consistent coding style and to ensure code quality. Each project should have a clear agreed standard that all members can comply with. . The most popular style guides include the Mozilla, AirBnb, Google, and the StandardJS style guide. AirBnb’s style guide focuses on user readability, while Google aims for concise code. The StandardJS guide is a more general set of guidelines that covers both readability and conciseness. There are a number of software tools that help enforce standards such as Prettier, ESLint, Husky JSHint. These can be used to check for errors in code and enforce standards, as well as additionally helping find common mistakes before being deployed. .

3. Application Structure

Modules can help organise code, and structure/thoughts to make it easier to maintain and debug -clearly defined interfaces, with separated logic, to deliver architect-ed solutions. ( eg Model View Controller ).

Some of the key features include :-

  • Encapsulation (bundling related code in a single source), can be used to restrict direct access to data and implementations of the bundled and related code from the code that uses them, implementation of the functionalities is hidden, so it can’t be manipulated by other parts of the code, and change is controlled/managed. Encapsulation makes your code cleaner, maintainable, and easier to understand, reuse, and test.
  • “Composability”, allowing functionality to be broken into pieces and re-assembled to form the whole function. It enables reuse of functions in other parts of the application, with benefits including: cleaner code, easier to reuse existing code, easier to separate concerns, and easy to understand.
  • Isolation: Modules allow development by composing small, focused functions, with each created, repaired, and thought of in isolation. Isolation makes it easier to understand, modify, and test code.
  • Readability: Code is it easier to read.
  • Organisation: When using modules, organisation occurs almost automatically because each part of the code is isolated.

4. Testing

Testing is essential for any software project, and important to carry out thoroughly before deployment. This can (obviously) help reduce bugs or issues before they become a problem for users. The most popular testing libraries/tools for Node.js applications includes Mocha, Jest, Jasmine and AVA ( covering a range of unit, system, use-case and performance based testing). Test-Based development is an important Agile approach that drives use case completion during Sprints using ‘success’ or end-state definitions built using test scripts or code. Once the test runs successfully, the code and hence the use-case or feature is complete.

5. Monitor Performance

Performance monitoring is essential to avoid problems with user experience, leading to security vulnerabilities. By monitoring performance we are able to support and enable applications to run smoothly at all times. Key items to cover include CPU usage metrics, events, Garbage collection, and Memory usage/leaks. There are a number of tools to support this for NodeJs, a few we cover here.

  • New Relic: A full-stack monitoring solution for Node.js applications, providing performance data and insights into how your code interacts with its environment.
  • PM2: A production process manager for Node.js applications, allowing you to monitor and manage your applications in real-time.
  • Appmetrics: An application performance monitoring tool for Node.js applications, providing insight into how your code is performing in production environments.
  • Keymetrics: A cloud-based service that helps developers monitor, debug and scale their Node.js applications in real-time.
  • Trace: A distributed tracing system for Node.js applications that helps developers to troubleshoot performance issues quickly and accurately.
  • Prometheus: An open-source monitoring solution for Node.js applications, providing metrics and alerting capabilities for application performance.

6. Security

It’s important to make sure that your application follows all the best practices for security, A brief overview is outlined below, but a more detailed examination of the key processes, guidelines, baselines and policies that cover application development will be covered later. Key things to look out for, as part of securing “Data at Rest”, “Data in Use” and “Data in Transit” :-

  • Ensuring secure authentication & authorisation of users and access to sensitive data.
  • Using HTTPS for all communications and encrypting any sensitive data stored in databases.
  • Limiting access to only trusted users with proper privileges.
  • Using built-in Node.js security features such as secure cookies and CSRF tokens.
  • Validating user input by using libraries such as Sanitizer and preventing SQL injections by using parameterised queries.
  • Patching: Keeping all dependencies up to date, including Node.js itself, as well as any third party modules used within the application.
  • Regularly scanning applications for vulnerabilities, such as with a Static or Dynamic application security testing tool set.

Security design should be included into every step of the development cycle, testing/challenging at each and every delivery step of the life-cycle. Integrating Security assurance into the delivery process is key, and driving, supporting or enhancing the security posture is important to ensure quality, reliability ( Confidentiality, Integrity and Availability ).

7. Syntax & Linting

Linting tools can be used to help ensure code follows the coding standards and is free of errors. These tools can be used to automatically check for any errors or issues, and help find them quickly. Running through source code and find issues relating to formatting irregularities, developer bugs, bad practices and style/syntax errors is time consuming and likely to fail if left to a ‘manual’ process. Common tools include JSLint, standardJS, JSHint, and ESLint.

8. Optimise

Optimising code will make it run faster and more efficiently, improving user experience. It can involve cleaning up unnecessary or improving existing code, to improve response times of applications, lower latency, error handling , throughput, and minimise CPU and memory resources. A number of areas you should consider includes;-:

  • Asynchronous Functions
  • Avoid Sessions and Cookies
  • Database Queries
  • Clustering
  • Reduce TTFB (Time to First Byte)
  • Error Trapping, Logging & Monitoring
  • Use HTTP/2
  • Multi-thread/Parallel Execution

We will look at these all in more detail later, but for now this gives you an overview of the areas that should be considered and factored into your application design.

9. Logging

Logging is essential for debugging Node.js applications. It can help track down errors or issues quickly and easily. It should be implemented at all levels of the application, from the front to back, Up and down the solution stack, and include all supporting components ( eg Middleware, proxy servers, database etc ).

10. CD/CI

Continuous Delivery/Continuous Integration help ensure that any changes made to the application are tested and check rapidly, reducing issues from occurring in production . CD/CI can also be used to measure progress, for teams to co-ordinate, and for a constant feed back as to quality, compliance and success. It has become critical in the modern delivery team to ensure performance, and to drive agility in the delivery cycle.

Summary

Each and every project requires careful tailoring (adaption) of these “Best Practices” to ensure the smoothest adoption, and best performance. Version Control, Common Coding Standards, Application Structure, Testing, Monitor Performance, Security, Syntax & Linting, Optimise, Logging and CD/CI should all be agreed and established as part of the project charter, and owned by the project & technical leadership. While tooling and process will often remain constant, each team within each project will have a different set of goals, priorities and skills/experiences — leading to the need to ensure the right alignment of each of these delivery methods against the project and the team. As part of the on-boarding process, each delivery team member should be made aware of their responsibilities, and in some cases trained to ensure they are able to fully adopt and help drive maturity in adoption.

Developing complex enterprise scale solutions efficiently and effectively, keeping costs under control, risks managed and deliveries on time, requires a focus on process, quality and standards. To achieve predictability, and agility these “Best Practices” methods and approaches should be adapted and adopt into your delivery process to help ensure business goals are met.

--

--

Gary Seymour
Gary Seymour

Written by Gary Seymour

CTO, Technology and Change Lead across enterprise, cloud and secure solutions. Central Government, Global Organisations, Technology Start-ups.

No responses yet