---
title: "Deploy Express.js + Passport.js starter"
description: "A simple service with fundamental components setup."
category: "Starters"
url: https://railway.com/deploy/7VIvXX
---

# Deploy Express.js + Passport.js starter

A simple service with fundamental components setup.

**[Deploy Express.js + Passport.js starter on Railway](https://railway.com/template/7VIvXX)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/7VIvXX/manifest.json

- **Creator:** edmond.w's Projects
- **Category:** Starters
- **Total deploys:** 76

## Template content

### service

- **Source:** https://github.com/railwayapp-templates/expressjs-passport-starter

## Documentation

# Railway's `Express.js` + `Passport.js` starter

This template deploys a simple service with fundamental components setup, built-in authentication/authorisation, and a fairly organised codebase.

# In this codebase

> Although important notes will be presented here, it is recommended to explore and emerge yourself in a `dfs` way, starting [here](https://github.com/edmondwinston/railway-nodejs/blob/main/src/index.js), as there exists plenty comments that will may or may not help you.

## Tech stack

`Express.js` application with [`Passport.js`](https://github.com/jaredhanson/passport) to protect your precious todos, as well as [`chai`](https://github.com/chaijs/chai) on [`mocha`](https://github.com/mochajs/mocha) for testing.

## Architecture notes

- Requests to your service flow pass your middlewares to your routes. Both of them are attached to the main application separately, and you can always add more in either [`src/core/attach-routes.js`](https://github.com/edmondwinston/railway-nodejs/blob/main/src/core/attach-routes.js) or [`src/core/attach-middlewares.js`](https://github.com/edmondwinston/railway-nodejs/blob/main/src/core/attach-middlewares.js).
- All the middlewares attached in [`src/core/attach-middlewares.js`](https://github.com/edmondwinston/railway-nodejs/blob/main/src/core/attach-middlewares.js) are application-level middlewares. They could all be categorised into the following types (1) **chore middlewares**, i.e. `cors`, `csrf`, etc. (2) **business middlewares**, which play some parts in the logic of your service.
- If a route-level middleware is what you need, [`src/modules/account/account.controller.js`](https://github.com/edmondwinston/railway-nodejs/blob/4bd82218e273149e9b7a56c077fd6fd034300570/src/modules/account/account.controller.js#L11) is an example implementation. _But remember_, `ensureAuthenticated` is placed in the common [`src/middlewares/index.js`](https://github.com/edmondwinston/railway-nodejs/blob/main/src/middlewares/index.js) because it will also be used in other routes and modules; if what you have is local to, say the `account` module, please put it there. (`account.middleware.js` is not a bad name)
- This codebase does not implement any logging mechanism, because only God knows what library you love. It also does not have `dotenv` built-in, because `Railway` injects environment variables at runtime. Do install if you are using this starter, not just reading it as a way to procrastinate your life (but thank you!).
- Other implementation details will be documented somewhere near the code.

## Testing

This is separated from the above section because I have actually tried a few testing frameworks, and `chai`'s interface is by far the most convenient to work with. Most of the time, you would want to test route handlers' business logic (TDD), or a fragment of the service flow (BDD), and `chai`'s `should` APIs or the normal `expect`s are really sweet. Anyway, just organise your test files as per the existing structure, but technically any file in the `__test__` directory that has the `.test.js` extension will be included if you run the predefined `test` script.

## Development

- The predefined `dev` script uses `Node.js` v18 experimental _--watch_ flag. If you cannot handle it, please implement `nodemon` or `pm2` yourself.
- Some JSDoc tags used are official ones, but rather a way of notating. They are the only personal thing in this starter, and please feel free to modify them to your team's specs, or your own liking.
- Have a glance at [this ESM guide](https://nodejs.org/api/esm.html) with a cup of coffee, there is a high chance you might learn something new.


## Similar templates

- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [caring-vibrancy](https://railway.com/deploy/caring-vibrancy) — Deploy and Host caring-vibrancy with Railway
- [Appsmith](https://railway.com/deploy/appsmith-1) — Low-code platform for internal tools, dashboards, and admin panels.

Open this page in a browser: https://railway.com/deploy/7VIvXX
