Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Nest.js: A Progressive Node.js Framework

You're reading from  Nest.js: A Progressive Node.js Framework

Product type Book
Published in Nov 2019
Publisher Packt
ISBN-13 9781800204737
Pages 317 pages
Edition 1st Edition
Languages
Authors (5):
Greg Magolan Greg Magolan
Profile icon Greg Magolan
Patrick Housley Patrick Housley
Profile icon Patrick Housley
Adrien de Peretti Adrien de Peretti
Profile icon Adrien de Peretti
Jay Bell Jay Bell
Profile icon Jay Bell
David Guijarro David Guijarro
Profile icon David Guijarro
View More author details

Table of Contents (16) Chapters

Preface
1. Introduction 2. Overview 3. Nest.js authentication 4. Dependency Injection system of Nest.js 5. TypeORM 6. Sequelize 7. Mongoose 8. Web sockets 9. Microservices 10. Routing and request handling in Nest.js 11. OpenAPI (Swagger) Specification 12. Command Query Responsibility Separation (CQRS) 13. Architecture 14. Testing 15. Server-side Rendering with Angular Universal

What is Nest.js?

There are so many available web frameworks, and with the advent of Node.js, even more have been released. JavaScript frameworks go in and out of style very quickly as web technologies change and grow. Nest.js is a good starting point for many developers that are looking to use a modern web framework because it uses a language that is very similar to that of the most used language on the web to this day, JavaScript. Many developers were taught programming using languages such as Java or C/C++, which are both strict languages, so using JavaScript can be a little awkward and easy to make mistakes given the lack of type safety. Nest.js uses TypeScript, which is a happy medium. It is a language that provides the simplicity and power of JavaScript with the type safety of other languages you may be used to. The type safety in Nest.js is only available at compile time, because the Nest.js server is compiled to a Node.js Express server that runs JavaScript. This is still a major advantage, however, since it allows you to better design programs error free prior to runtime.

Node.js has a rich ecosystem of packages in NPM (Node Package Manager). With over 350,000 packages, it’s the world’s largest package registry. With Nest.js making use of Express, you have access to each and every one of these packages when developing Nest applications. Many even have type definitions for their packages that allow IDE’s to read the package and make suggestions/auto fill in code that may not be possible when crossing JavaScript code with TypeScript code. One of the largest benefits of Node.js is the huge repository of modules that are available to pull from instead of having to write your own. Nest.js includes some of these modules already as part of the Nest platform, like @nestjs/mongoose, which uses the NPM library mongoose. Prior to 2009, JavaScript was mainly a front-end language, but after the release of Node.js in 2009, it spurred the development of many JavaScript and TypeScript projects like: Angular, React, and Vue, among others. Angular was a heavy inspiration for the development of Nest.js because both use a Module/Component system that allows for reusability. If you are not familiar with Angular, it is a TypeScript-based front-end framework that can be used cross-platform to develop responsive web apps and native apps, and it functions a lot like Nest does. The two also pair very well together with Nest providing the ability to run a Universal server to serve pre-rendered Angular web pages to speed up website delivering times using Server-Side Rendering (SSR) mentioned above.

About the example

This book will reference a working Nest.js project that is hosted on GitHub at (https://github.com/backstopmedia/nest-book-example). Throughout the book, code snippets and chapters will reference parts of the code so that you can see a working example of what you are learning about. The example Git repository can be cloned within your command prompt.

git clone https://github.com/backstopmedia/nest-book-example.git

This will create a local copy of the project on your computer, which you can run locally by building the project with Docker:

docker-compose up

Once your Docker container is up and running on port localhost:3000, you will want to run the migration before doing anything else. To do this run:

docker ps

To get the ID of your running Docker container:

docker exec -it [ID] npm run migrate up

This will run the database migrations so that your Nest.js app can read and write to the database with the correct schema.

If you don’t want to use Docker, or cannot use Docker, you can build the project with your choice of package managers such as npm or yarn:

npm install

or

yarn

This installs the dependencies in your node_modules folder. Then run:

npm start:dev

Or the following to start your Nest.js server:

yarn start:dev

These will run nodemon, which will cause your Nest.js application to restart if any changes are made, saving you from having to stop, rebuild, and start your application again.

About the authors

  • Greg Magolan is a Senior Architect, Full-Stack Engineer, and Angular Consultant at Rangle.io. He has been developing enterprise software solutions for over 15 years working for companies suchas Agilent Technologies, Electronic Arts, Avigilon, Energy Transfer Partners, FunnelEnvy, Yodel andACM Facility Safety.
  • Jay Bell is the CTO of Trellis. He is a Senior Angular developer that uses Nest.js in production to develop industry leading software to help non-profits and charities in Canada. He is a serial entrepreneur that has developed software in a large range of industries from helping combat wildfires with drones to building mobile apps.
  • David Guijarro is a Front-End Developer at Car2go Group GmbH. He has a wide experience working within the JavaScript ecosystem. He has successfully built and led multi-cultural, multi-functional teams.
  • Adrien de Peretti is a Full-Stack JavaScript Developer. He is passionate about new technologies and is constantly looking for new challenges, and is especially interested in the field of Artificial Intelligence and Robotics. When he is not front of his computer, Adrien is in nature and playing different sports.
  • Patrick Housley is a Lead Technologist at VML. He is an IT professional with over six years of experience in the technology industry and is capable of analyzing complex issues spanning multiple technologies while providing detailed resolutions and explanations. He has strong front-end development skills with experience leading development teams in maintenance and greenfield projects.
lock icon The rest of the chapter is locked
Next Chapter arrow right
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}