[Node.js] Build microservices in Node.js with micro

micro is a small module that makes it easy to write high performance and asynchronous microservices in Node.js. This video will introduce you to micro by building a tiny service that responds to all requests.

 

const {send} = require('micro');
const sleep = require('then-sleep');

// Just send method
module.exports = (req, res) => {
    send(res, 200, 'Hello World!')
}

// Just use return
module.exports = (req, res) => {
    return 'Hello World return';
}

// Easy to use async await
module.exports = async function(req, res){
    await sleep(5000)
    send(res, 200, 'Ready!')
}

 

Microservices architecture is a style of software architecture. As the name suggests, microservicess refers to small services. For a large implementation, this means breaking the system into really small, independent services. Alternative to monolithic architecture (where the entire system is considered as a single big, interwoven segment), microservices approach is getting more and more popular with large, complex applications that have a very long lifecycle, which require changes at regular intervals. Microservices approach allows this type of changes with ease as only a part of the system undergoes changes and change control is easy. An example of such large system can be an online store―includes user interface, managing product catalog, processing orders, managing customer’s account. In a microservices architecture each of these tasks will be divided and into smaller services. Also, these services will be further broken down into independent services―for user interface, there will be separate services for input, output, search bar management, and so on. Similarly, all other tasks can be divided in very small and simple services. What you will learn Identify where the microservice oriented architectures can tackle the most common problems in the software used by the big organisations. Re-architecture an existing monolithic system into a microservices oriented software. Build robust and scalable microservices using Seneca and Node.js. Testing of the microservices in insolation in order to create a solid system. Deploy and manage microservices using PM2 Monitoring the health of a microservice (CPU, memory, I/O…) and how the degradation of the performance in one microservice could degrade the performance of full system.
This book is a hands-on guide to start writing microservices using Node.js and the most modern frameworks, especially Seneca and PM2. In the chapters, we will discuss how to design, build, test, and deploy microservices using the best practices. We will also discuss a valuable lesson: how to make the right level of compromise in order to avoid over-designing and get the business requirements aligned with the technical solutions. What this book covers Chapter 1, Microservices Architecture, discusses the pros and cons of microservices- oriented architectures. It will be the foundation for the rest of the book. Chapter 2, Microservices in Node.js – Seneca and PM2 Alternatives, introduces Node.js, Seneca, and PM2. In it, we will discuss the structure of a Node.js application and how to run it using PM2. We will also dive into a few alternatives to Seneca and PM2. Chapter 3, From the Monolith to Microservices, covers how to tackle the organic growth (unplanned software changes) using microservices. We will also talk about how to split a monolithic application into microservices. Chapter 4, Writing Your First Microservice in Node.js, explains how to write our first microservice. Chapter 5, Security and Traceability, covers how security and traceability are two important characteristics of modern systems. We need to keep the information secure and the actions traceable. In this chapter, we will discuss how to do it using Seneca. Preface [ viii ] Chapter 6, Testing and Documenting Node.js Microservices, introduces using the main frameworks for testing on Node.js: Mocha and Chai. We will also make use of Sinon (another framework) to mock services. Swagger will be our choice for documenting microservices. Chapter 7, Monitoring Microservices, covers using PM2 to monitor our microservices. We will use it along with Keymetrics to get the maximum benefit of such an advanced tool. Chapter 8, Deploying Microservices, explains how, using PM2, we are going to learn to deploy microse
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值