express
Complete deployment guide for express on NStrim
Overview
Express.js is a fast, unopinionated, minimalist web framework for Node.js. It provides robust features for building web applications and REST APIs with a focus on simplicity and flexibility.
Before You Start
Make sure you have your dashboard open - you'll need the Git credentials displayed there. This template includes Prisma ORM, Sequelize, MySQL2, JWT authentication, Socket.io, and EJS templating.
Quick Start
1
Create Repository from Template
On your dashboard, go to the Tools & Deployment tab. Click the "New Repository" button, select the Express template from the dropdown, enter a repository name and subdomain, then click "Create Repository".
2
Clone Your Repository
git clone https://<git-server>/<username>/<repo-name>.git
cd <repo-name>
3
Install Dependencies
npm install
4
Start Development Server
npm run dev
Server runs on http://localhost:3000 by default.
5
Push Your Changes
git add .
git commit -m "Initial setup"
git push origin main
Every push to Git automatically deploys your application. Check your Module Work URL on the dashboard to see your live site.
Local Development with Docker
If you don't have Node.js installed locally, you can use Docker to run Express commands.
What is Docker?
Docker creates isolated "containers" with all the software you need (Node.js, npm) without installing them on your computer.
Running Commands with Docker
# Run npm install
docker run --rm -v $(pwd):/app -w /app node:lts npm install
# Run development server
docker run --rm -v $(pwd):/app -w /app -p 3000:3000 node:lts npm run dev
Project Structure
├── src/
│ ├── controllers/ # Request handlers
│ ├── middleware/ # Custom middleware
│ ├── models/ # Database models
│ ├── routes/ # Route definitions
│ └── server.js # Express app setup
├── views/ # EJS template files
├── public/ # Static files
├── prisma/ # Prisma schema
├── package.json # Dependencies
└── Dockerfile # Docker config
Common Tasks
Creating a Route
const express = require('express');
const router = express.Router();
router.get('/users', (req, res) => {
res.json({ message: 'Get all users' });
});
module.exports = router;
Using Prisma ORM
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
const users = await prisma.user.findMany();
const user = await prisma.user.create({
data: { name: 'John', email: 'john@example.com' }
});
Useful Commands
npm run dev
Start dev server with nodemon
npm start
Start production server
npx prisma migrate dev
Run Prisma migrations
Troubleshooting
Database connection failed
Solution: Check DATABASE_URL in .env file. Format: mysql://user:password@host:port/database
Port 3000 already in use
Solution: Change PORT in .env file or stop the other process.
Deployment Workflow
Code Change
git push
npm install
Live!
For more information, visit the official Express.js Documentation.