Building an Express Application Chapter 2
We can modify this structure as per our needs and requirements as well. This is very handy
when we are on a tight deadline and want to build an application in a day or so. The
process is extremely simple.
express-generator is only one of many tools that are available to create
a scaffold or a modular structure of an express application. Each generator
tool may have its own way of building the file structure as per their
standard which can be easily customized.
If you are a beginner and want to understand how the folder structure works, I recommend
you build the application from scratch. We will be discussing this further in this chapter.
To get started, first we need to learn more about Node.js before diving into Express.js.
Introduction to Node.js
Node.js is a JavaScript runtime build on a JavaScript engine. It is an open source framework
used for server-side management. Node.js is lightweight and efficient and runs on various
platforms, such as Windows, Linux, and macOS.
Node.js was created by Ryan Dahl in 2009. JavaScript used to be used mostly for client-side
scripting, but Node.js enables JavaScript to be used on the server side as well. The invention
of Node.js introduced the use of a single programming language in web applications.
Node.js brings with it a lot of benefits, some of which are as follows:
Event-driven programming: It means changing the state of an object from one to
another. Node.js uses event-driven programming, which means it uses a user's
interactive actions, such as mouse clicks, and key presses, to change the state of
objects.
Non-blocking I/O: The non-blocking I/O, or non-synchronous I/O, means an
asynchronous I/O. A synchronous process waits until the current running
process is completed and, hence, blocks the process. On the other hand, the
asynchronous process does not need to wait for that process to finish, which
makes it fast and reliable as well.
Single threading: Single threading means that JavaScript runs in only a single
event loop. Since an asynchronous process allows us to have multiple processes
concurrently, it may seem like all these processes run in their own specific
thread. But Node.js handles asynchronous a little differently. The event loop in
Node.js triggers the next callback function that is scheduled for execution after
the corresponding event has occurred.