Express.js remains a go-to entry point for many who are starting with JavaScript in the back-end. For years, the simplest way to set up a Node.js project with Express was to run the command npx express-generator
.
However, if you try using express-generator
today, the result after installing dependencies with npm install
is this:
In other words, outdated and vulnerable package versions (and no, running npm audit fix --force
won’t help).
Fortunately, there’s at least one alternative (if you know of others, feel free to share in the comments). This option is a project called create-express-app, which generates a project with updated dependencies and more. The imports follow the ES6 standard, and the tool offers project setup options that include TypeScript and recent template engine options.
To create a project with Express.js using create-express-app
, simply run the following in your terminal:
npx @kba-tools/create-express-app
On the first run, as with any package executed with npx
, you’ll be asked to confirm if you want to continue. Type Y.
Next, the utility will ask you to name your project.
As mentioned, create-express-app
offers the option to set up the project with TypeScript. To select it, use the down arrow and press Enter.
Though widely used for building RESTful APIs, Express.js also integrates with template engines if you want to use the framework as a full-stack solution. When asked which template engine you’d like, leave the default “None” if your goal is to build only a Node.js back-end.
You can also configure your project to use a package manager other than npm
if you prefer.
These are all the prompts. The tool will then install all dependencies, leaving the project ready to run. Just navigate to the newly created project folder and execute npm run dev
in the terminal.
Notice that no vulnerabilities are found once the dependencies are installed, as create-express-app
ensures the latest package versions are used.
Everything’s ready. Happy coding!
Featured image credits: externlabs