Express is mature, minimal, and an open source web framework for making web applications and apis.
Setting Up Express
To create a new workspace with Express, run the following command:
1 npx create-nx-workspace --preset=express
Adding Express to an Existing Project
Install the express plugin
1npm install --save-dev @nrwl/express
1yarn add --dev @nrwl/express
Add a new application to your workspace with the following command:
1nx g @nrwl/express:app my-app
Serve the application by running
1nx serve my-app
This starts the application on localhost:3333/api by default.
Express does not come with any library generators, but you can leverage the
@nrwl/jsplugin to generate a Node.js library for your express application.
The Express application generator has an option to configure other projects in the workspace to proxy API requests. This
can be done by passing the
--frontendProject with the project name you wish to enable proxy support for.
1nx g @nrwl/express:app <express-app> --frontendProject my-react-app
You can run unit tests with:
1nx test <project-name>
Express projects can be built with:
1nx build <project-name>
Build artifacts will be found in the
dist directory under
apps/<project-name> by default. Customize the build
configuration by editing
outputPath in the project configuration.
Waiting for Other Tasks
You can wait for other tasks to run before serving the express app which can be handy for spinning up various services the application depends on— for example, other apis in a microservice.
waitUntilTargets option with an array of targets (format:
"project:target") executes those tasks
before serving the Express application.
Here is a list of all the executors and generators available from this package.