Gathering detailed insights and metrics for express-mock-restful
Gathering detailed insights and metrics for express-mock-restful
Gathering detailed insights and metrics for express-mock-restful
Gathering detailed insights and metrics for express-mock-restful
express mock middleware that creates mocks for REST APIs. It will be helpful when you try to test your application without the actual REST API server.
npm install express-mock-restful
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
2 Stars
19 Commits
1 Forks
1 Watchers
3 Branches
1 Contributors
Updated on Apr 28, 2023
Latest Version
1.1.3
Package Id
express-mock-restful@1.1.3
Unpacked Size
25.09 kB
Size
5.71 kB
File Count
22
NPM Version
6.14.6
Node Version
12.18.4
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
express-mock is a express middleware that creates mocks for REST APIs. It will be helpful when you try to test your application without the actual REST API server.
Features:
🔥 Built in support for hot Mocker file replacement.
🚀 Quickly and easily configure the API via JSON.
1npm install express-mock-restful --save-dev
express-mock-restful dev support mock, configured in mocker.js
. refresh mock with require('express-mock-restful').refresh api
1const mockMap = { 2 'GET /api/user': { 3 id: 1, 4 username: 'kenny', 5 sex: 6, 6 }, 7 'GET /api/user/list': [ 8 { 9 id: 1, 10 username: 'kenny', 11 sex: 6, 12 }, 13 { 14 id: 2, 15 username: 'kenny', 16 sex: 6, 17 }, 18 ], 19 'POST /api/login/account': (req, res) => { 20 const { password, username } = req.body; 21 if (password === '888888' && username === 'admin') { 22 return res.json({ 23 status: 'ok', 24 code: 0, 25 token: 'sdfsdfsdfdsf', 26 data: { 27 id: 1, 28 username: 'kenny', 29 sex: 6, 30 }, 31 }); 32 } else { 33 return res.json({ 34 status: 'error', 35 code: 403, 36 }); 37 } 38 }, 39 'DELETE /api/user/:id': (req, res) => { 40 console.log('---->', req.body); 41 console.log('---->', req.params.id); 42 res.send({ status: 'ok', message: '删除成功!' }); 43 }, 44}; 45module.exports = mockMap;
1const express = require('express'); 2const path = require('path'); 3const chokidar = require('chokidar'); 4const app = express(); 5+ const apiMocker = require('express-mock-restful'); 6 7+ const mockFile = path.resolve(__dirname, './mocker.js'); 8+ app.use(apiMocker(require(mockFile))); 9// or app.use(apiMocker({ entry: './mocker.js' })); 10 11app.listen(3000); 12console.log('server listen on http://127.0.0.1:3000/');
1const express = require('express'); 2const path = require('path'); 3const chokidar = require('chokidar'); 4const app = express(); 5+ const apiMocker = require('express-mock-restful'); 6 7+ const mockFile = path.resolve(__dirname, './mocker.js'); 8+ app.use(apiMocker(require(mockFile))); 9 10// watch file change refresh mock setting 11+ chokidar.watch(mockFile).on('all', (event, path) => { 12+ try { 13+ delete require.cache[require.resolve(mockFile)]; 14+ apiMocker.refresh(require(mockFile)); 15+ console.log('refresh...'); 16+ } catch (err) { 17+ console.log(err); 18+ } 19+ }); 20 21app.listen(3000); 22console.log('server listen on http://127.0.0.1:3000/');
To use api mocker on your Webpack projects, simply add a setup options to your webpack-dev-server options:
Change your config file to tell the dev server where to look for files: webpack.config.js
.
1const path = require('path'); 2const HtmlWebpackPlugin = require('html-webpack-plugin'); 3+ const apiMocker = require('express-mock-restful'); 4 5module.exports = { 6 mocker: { 7 app: './src/index.js', 8 print: './src/print.js' 9 }, 10 devtool: 'inline-source-map', 11+ devServer: { 12+ ... 13+ before(app){ 14+ app.use(apiMocker(require('./mocker/index.js')); 15+ } 16+ }, 17 plugins: [ 18 new HtmlWebpackPlugin({ 19 title: 'Development' 20 }) 21 ], 22 output: { 23 filename: '[name].bundle.js', 24 path: path.resolve(__dirname, 'dist') 25 } 26};
Must have a file suffix! For example: ./mocker.js
.
Let's add a script to easily run the dev server as well: package.json
1 { 2 "name": "development", 3 "version": "1.0.0", 4 "description": "", 5 "main": "webpack.config.js", 6 "scripts": { 7 "test": "echo \"Error: no test specified\" && exit 1", 8+ "start": "webpack-dev-server --open", 9 "build": "webpack" 10 }, 11 "keywords": [], 12 "author": "", 13 "license": "MIT", 14 "devDependencies": { 15 .... 16 } 17 }
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More