Express | WebpackThe ultimate guide

Chapter I - Scaffolding a new project

There are many ways to create a new Express project, but in this book we'll use the official Express generator tool to generate a new project.

Create a new Express project

Use the generator to create your project:

npm i express-generator -g
express -v twig my-project
cd my-project

The generator will create a my-project folder and put a basic Express app in it. Let's go over the files created:

Take a look at the commit for this step

Housekeeping

The fact you're using Javascript for both server and client is pretty neat. However, it can become confusing if you don't keep things separated. Separating client and server will also make defining the watched files easier for the Express HMR in chapter 5.

This is why we'll move all Express-related files to a new folder /src/server:

You'll also have to update references to this file:

commit for this step

Adding .gitignore

If you want to use git in your project, consider making a .gitignore file first. I used the PHPStorm generator but the most important rules are:

/dist
/node_modules

commit for this step

Conclusion

We used the Express generator to create a new Express project and made a few preparations before we add the client-side configuration. You should be able to start the app and see a test page.

yarn install
yarn start

Point your browser to (http://localhost:3000) and see the app in action!

After completing this chapter, your app should look like the sample app in the chapter-1 tag.

Further reading


» Continue to chapter 2 - Setup Webpack for JS build with babel