1. npm init --y //Initialise and Configure Our Project
2. npm install express --save //Install express and other dependencies
3. npm install body-parser --save //body parsing middleware
4. npm install --save-dev nodemon //tool that helps develop node.js based applications by automatically restarting the node application when file changes
5. touch server.js //Here Server Code
http://localhost:5000
6. npm start
...
7.npm i nano

server.js

const express = require('express');
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
//route
const blog = require('./routers/blog');
app.use('/api/v1/blog', blog);
//end_route
const port = process.env.PORT || 8002;app.listen(port, () => {
console.log(`Node Js server running on port: ${port}`);
});

routers/blog.js

const path = require('path');
const express = require('express');
const router = express.Router();
const couch = require('../couchdb');
//===========create_table_blog=======(async function createDb() {
try {
await couch.db.create('blog')
} catch (ex) {
}
})()
const blog = couch.use('blog')//===========end_create_table_blog=======router.get('/', async (req, res) => { try {
var data = {
'success': true,
'message': 'get all content',
};
res.send(data);
} catch (ex) {
res.status(400).send({ code: 400, message: ex.message })
}
});module.exports = router;
const nano = require('nano');const url = 'http://admin:piyas@127.0.0.1:5984';
console.log('database connected:', url);
console.log('env:', process.env.NODE_ENV);
module.exports = nano(url);

http://127.0.0.1:8002/api/v1/blog

Software Engineer