MongoDB, Express, NodeJS template with Passport authentication.
- Clone repo
npm i
npm i -g pm2
- Remeber to change config in
ecosystem.config.js
. pm2 start
- To view logs:
pm2 logs
module.exports = {
apps: [
{
name: "men-pp-template",
script: "./index.js",
watch: true,
args: ["--color"],
instances: 1,
exec_mode: "cluster",
env: {
HTTP_PORT: 8080,
NODE_ENV: "development",
MONGO_URI: `mongodb://localhost:27017/sample-db`,
JWT_SECRET: "supersecret",
BCRYPT_ROUNDS: 10,
VERIFY_ALGORITHM: ["HS256"],
TOKEN_ISSUER: "server",
JWT_EXPIRES_IN: "1h",
SIGN_ALGORITHM: "HS256"
}
}
]
};
File | Functionality |
---|---|
/controllers/index.js |
To add API endpoints |
/middleware/index.js |
To add middlewares to the Express app |
/models/index.js |
To add Mongoose schemas and @Hapi/Joi validation schemas |
/services/index.js |
To add functions to the controllers |
/keys/index.js |
To add ENV variables |
Method | Endpoint | Description | Examples |
---|---|---|---|
GET |
/ |
Welcome message | http:localhost:8080/ |
GET |
/usernames |
Get all usernames (needs authentication) | http:localhost:8080//usernames |
POST |
/sign-up |
Sign up | http:localhost:8080//sign-up Body parameters: {"username" : "Niweera", "password" : "secret"} |
POST |
/sign-in |
Sign in | http:localhost:8080//sign-in Body parameters: {"username" : "Niweera", "password" : "secret"} |