
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
A boilerplate/starter project for quickly building RESTful APIs using Node.js, Express, and Mongoose.
Clone project to create your project, simply run:
git clone https://github.com/MrBrown6210/nodejs-express-mongoose-typescript-boilerplate.git <project-name>
Set the environment variables: (You can see all enviroment key at src/config/config)
cp .env.example .env
Running locally:
yarn dev
building:
yarn build
Running production (build before use):
yarn start
Testing:
# run all unit tests
yarn test
# run all unit tests in watch mode
yarn test:watch
# run unit tests coverage
yarn test:coverage
# run all e2e tests
yarn test:e2e
# run all e2e tests in watch mode
yarn test:e2e:watch
The environment variables can be found and modified in the .env
file. They come with these default values:
# Port number
APP_PORT=9000
# Prefix app path
APP_PREFIX_PATH=/
# JWT
# JWT Secret
JWT_SECRET=somerandomkeyherena
# JWT Expire
JWT_EXPIRE=1y
# Database config
# If you want to use database URI with DB_URI
DB_URI=mongodb://localhost:27017/Mocks
# If you want to use seperate database URI
DB_USER=root
DB_USER_PWD=secret
DB_HOST=localhost
DB_NAME=conduit
DB_PORT=27017
This project don't have controllers and services folders because we want to minimalized. If you want them, you can create it
src\
|--config\ # Environment variables and configuration related things
|--middlewares\ # Custom express middlewares
|--models\ # Mongoose models (data layer)
|--routes\ # Routes
|--utils\ # Utility classes and functions
|--app.js # Express app
|--index.js # App entry point
The app has a centralized error handling mechanism.
Routes should try to catch the errors and forward them to the error handling middleware (by calling next(e)
).
router.post('/login', async (req, res, next) => {
try {
const { email, password } = req.body
const user = await User.findOne({ email })
if (!user || !user.validPassword(password))
throw new ApiError(httpStatus.UNPROCESSABLE_ENTITY, 'Invalid email or password')
res.json(user.toAuthJSON())
} catch (e) {
next(e)
}
})
The error handling middleware sends an error response, which has the following format:
{
"code": 401,
"message": "Invalid email or password"
}
When running in development mode, the error response also contains the error stack.
To require authentication for certain routes, you can use the authenticate
from passportjs
router.post('/', authenticate(['jwt'], { session: false }), async (req, res, next) => {
try {
const store = new Store(req.body.store)
await store.save()
res.json(store)
} catch (e) {
next(e)
}
})
Import the logger from src/config/logger.ts
. It is using the Winston logging library.
Logging should be done according to the following severity levels (ascending order from most important to least important):
import logger from '@/config/logger'
logger.error('message'); // level 0
logger.warn('message'); // level 1
logger.info('message'); // level 2
logger.http('message'); // level 3
logger.verbose('message'); // level 4
logger.debug('message'); // level 5
In production mode, only info
, warn
, and error
logs will be printed to the console.
Linting is done using ESLint and Prettier.
In this app, ESLint is configured to follow the Airbnb JavaScript style guide with some modifications. It also extends eslint-config-prettier to turn off all rules that are unnecessary or might conflict with Prettier.
To modify the ESLint configuration, update the .eslintrc.json
file. To modify the Prettier configuration, update the .prettierrc.json
file.
To prevent a certain file or directory from being linted, add it to .eslintignore
and .prettierignore
.
To maintain a consistent coding style across different IDEs, the project contains .editorconfig
Contributions are welcome! Please check out the contributing guide.
FAQs
TimeEdit authentication backend
We found that te-auth-be demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.