How to create an expressjs based RESTful API using express-ve package.

mkdir expressive-blog && cd expressive-blog
yarn init -y
yarn add express-ve
touch index.js
require('dotenv').config()
const { createContainer } = require('../../../node-packages/node-ioc/index')

createContainer().then((container) => {
const { app } = container
app.listen(4040, () => {
console.log('Listening at port 4040')
})
})

{
"name": "demo",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"dotenv": "^16.0.0",
"express-ve": "^0.0.31"
},
"scripts": {
"start": "nodemon index.js"
}
}

Routes

module.exports = (container) => {
return {
route: (req, res) => {
return res.json({ message: 'Welcome to the API' })
}
}
}
module.exports = {
prefix: 'api'
}
// /v1/blog__post.js
module.exports = (container) => {
return {
route: (req, res) => {
return res.status(401).json({ message: 'Blog has been created' })
}
}
}
// db/blog.js
module.exports = (mongoose) => {
const BlogSchema = new mongoose.Schema({
title: {type: String, required: true},
content: {type: String, required: true},
}, { timestamps: true })

mongoose.model('Blog', BlogSchema)
}
// config/routes.js
module.exports = {
prefix: 'api',
resources: ['v1/blog']
}
module.exports = {
blog: {
read: true,
write: true,
delete: false,
},
}

--

--

--

አሳቢና ጸሓፊ ነኝ። በተለይም ኃሳብ ከሰዎች ጋር ባለው ትስስርና እንዴት ከእውነታ ጋር መገናኘት እንደሚችል መመራመር እወዳለሁ። በጽሑፎቼም እነዚህን ግኝቶቼን አሰፍራለሁ።

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Build a JAMstack-Powered Website in 4 Steps

9 Ways JavaScript Can Drive You Crazy

How to Apply Dark Mode Using Material-UI

Create a reusable confirmation dialog in Angular 7, using Angular Material

Morpheus Experiment — Part I

Initial Auth with Angular & OAuth2

Docker for Front-End Developers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Merhawi Fissehaye

Merhawi Fissehaye

አሳቢና ጸሓፊ ነኝ። በተለይም ኃሳብ ከሰዎች ጋር ባለው ትስስርና እንዴት ከእውነታ ጋር መገናኘት እንደሚችል መመራመር እወዳለሁ። በጽሑፎቼም እነዚህን ግኝቶቼን አሰፍራለሁ።

More from Medium

CRUD app with Node, Express, and MongoDB

Reuse RabbitMQ connection

How to Create a Simple REST API Using TypeScript And NodeJs

Two Important Concepts of Node js