Basically, this is a boilerplate of:
- MongoDB
- Express.js
app
- ESLint and Prettier integrated
- API Docs generation
- Basic sanitization of
parameters
for APIs
for deta.sh
. Although, pretty sure, it will also work for other platforms too.
Something like this: helloworld
Get to know what Deta.sh really is.
In short, a better Heroku.
This boilerplate uses apidoc
to generate necessary docs for your micro service API. So get to know the basics.
In short, /src/templates/apidocs_template
should not be touched. Same advice goes for /src/static_files
.
npm run dev
would generate the docs
and you can then do local development.
In the .env
file:
- set the
MONGODB_URL
your connection string. - set the
DB_COLLECTION
your collection name i.e.helloworld
etc.
try {
const db = await mongodb.connect(mongodbUrl, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
if (isTest === false) {
log.notify(true, null, 'Successfully connected to MongoDB')
}
this.itSelf = db.db(mongodbName)
this.myCollection = this.createCollection(whateverNameOfYourCollection)
} catch (err) {
log.notify(
. . .
}
Here replace the following line
this.myCollection = this.createCollection(whateverNameOfYourCollection)
with your own collection name.
index.js
~ this should not be touched or you risk breaking deta.sh deployment./src/app.js
~ this is your mainapp
and do whatever tweaks and changes needed.