Giter Site home page Giter Site logo

kunalkapadia / express-mongoose-es6-rest-api Goto Github PK

View Code? Open in Web Editor NEW
2.9K 113.0 695.0 304 KB

:collision: A boilerplate application for building RESTful APIs Microservice in Node.js using express and mongoose in ES6 with code coverage and JsonWebToken Authentication

Home Page: http://kunalkapadia.github.io/express-mongoose-es6-rest-api/

License: MIT License

JavaScript 95.16% Shell 2.19% Dockerfile 2.65%
es6 express node mongoose babel eslint jsonwebtoken bluebird coverage mongodb

express-mongoose-es6-rest-api's People

Contributors

dalanir avatar delsner avatar eyalcohen4 avatar greenkeeperio-bot avatar hananbo avatar kunalkapadia avatar maxsbelt avatar osahner avatar rafaelhz avatar readmecritic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

express-mongoose-es6-rest-api's Issues

path issue

When running your code i get the following error:

    /express-mongoose-es6-rest-api/node_modules/kew/kew.js:198
          throw e
          ^
    TypeError: Path must be a string. Received undefined

I am working on figuring out what the problem is now, but thought I'd post it here so you would be aware of it.

I cloned it down, cd'd into it, ran NPM install, and then DEBUG=express-mongoose-es6-rest-api:* npm start

So, I am assuming there is some variable that isn't being set, because of the udefined. Still tracing it. I'll update this once I find something.

express validation on param converter

Hi,

How I can use validation in a param converter?
I wanted to use Joi.objectId () to validate that this is a mongodb valid id

router.route('/:id')
  /** GET /api/users/:userId - Get user */
  .get(validate(paramValidation.get),userCtrl.get)

  /** PUT /api/users/:userId - Update user */
  .put(validate(paramValidation.updateUser), userCtrl.update)

  /** DELETE /api/users/:userId - Delete user */
  .delete(validate(paramValidation.deleteUser), userCtrl.remove);

/** Load user when API with userId route parameter is hit */
router.param('id', userCtrl.load);

Thanks and regards

Server not refreshing correctly.

First time for using this package. After following the install procedures, getting the server up, running and listening, I have tried to post a user to test the next step of the API... The response I got was....


{
  "message": "\"mobileNumber\" with value \"07834368491\" fails to match the required pattern: /^[1-9][0-9]{9}$/",
  "stack": "Error: \"mobileNumber\" with value \"07834368491\" fails to match the required pattern: /^[1-9][0-9]{9}$/\n    at APIError.ExtendableError (E:\\napi\\dist\\server\\helpers\\APIError.js:35:11)\n    at new

Which is legitimate, however - even when I change the user model to the following:

const UserSchema = new mongoose.Schema({
  username: {
    type: String,
    required: true
  },
/*  mobileNumber: {
    type: String,
    required: true
  },*/
  createdAt: {
    type: Date,
    default: Date.now
  }
});

I still get the same error - this happens despite doing a clear restart of the server (which I think it does automatically anyway) or even the computer. Any ideas would be greatly appreciated.

Thanks

Dan

Error: API not found at APIError.ExtendableError

Help. I just clone it and run it and got this error below. Please help. Thanks.
Error: API not found at APIError.ExtendableError

{"message":"Not Found","stack":"Error: API not found\n at APIError.ExtendableError (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/dist/server/helpers/APIError.js:35:11)\n at new APIError (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/dist/server/helpers/APIError.js:63:77)\n at /Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/dist/config/express.js:122:13\n at Layer.handle as handle_request\n at trim_prefix (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:312:13)\n at /Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:280:7\n at Function.process_params (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:330:12)\n at next (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:271:10)\n at Layer.handle as handle_request\n at trim_prefix (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:312:13)\n at /Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:280:7\n at Function.process_params (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:330:12)\n at next (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:271:10)\n at /Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express-winston/index.js:291:9\n at Layer.handle as handle_request\n at trim_prefix (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:312:13)\n at /Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:280:7\n at Function.process_params (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:330:12)\n at next (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/express/lib/router/index.js:271:10)\n at cors (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/cors/lib/index.js:178:7)\n at /Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/cors/lib/index.js:228:17\n at originCallback (/Users/joseph/Documents/node-heroku/express-mongoose-es6-rest-api/node_modules/cors/lib/index.js:217:15)"}

Node v6.3.1
NPM v3.10.3

Pass req.body directly into mongoose model?

I notice that this project reads every single parameter from req.body into a new object just to create the database instance from it. Example from user.controller.js:

function create(req, res, next) {
  const user = new User({
    username: req.body.username,
    mobileNumber: req.body.mobileNumber
  });

  user.save()
    .then(savedUser => res.json(savedUser))
    .catch(e => next(e));
}

Is there a reason for that? Why not simply to new User(req.body)?

Great workflow to develop

Hello,
I am using express-mongoose-es6-rest-api to build my REST API,
thanks for the product I am very like it!

But issue that it requires enough time to me to debug any error while development and write code for next feature

My workflow is:

  1. Run npm start with nodemon in one console
  2. Run npm test in other console (with nodemon, nodemon /usr/bin/gulp test)
  3. I write one test for feature and I expect the test to be not passed (red)
  4. I do one small change and see - test is passed (green) or still red
  5. If test is still red then I change my code again until the test becomes green
  6. When test is green then I repeat 3-6 steps for next feature

The issue is that each time when I change my code it requires >=7 seconds to get javascript code from source (clean, link, copy, babel) (1) and also >=3 seconds to run tests (2). It is >=10 seconds total per iteration. So just to change one word in my code or add one space I need to wait within 10 seconds each time. I can disable link task while development and run it before commit only but (1) task still requires >=4 seconds and it is not enough fast

Could you offer me best approach or workflow to debug and develop?

Coverage failed

Hi, I am having problems with the plugin gulp -istanbul.

When I do commit, all tests are passed but the process fails to make the coverage

  38 passing (4s)

=============================== Coverage summary ===============================
Statements   : 89.46% ( 1163/1300 ), 75 ignored
Branches     : 84.71% ( 277/327 ), 85 ignored
Functions    : 73.48% ( 241/328 ), 1 ignored
Lines        : 85.86% ( 777/905 )
================================================================================
[13:58:10] 'test' errored after 9.18 s
[13:58:10] Error in plugin 'gulp-istanbul'
Message:
    Coverage failed
[13:58:10] Error in plugin 'run-sequence(test)'
Message:
    Coverage failed
Stack:
    at finish (/home/sergio/proyects/instangular-rest-api/node_modules/run-sequence/index.js:56:13)
    at Gulp.onError (/home/sergio/proyects/instangular-rest-api/node_modules/run-sequence/index.js:67:4)
    at emitOne (events.js:82:20)
    at Gulp.emit (events.js:169:7)
    at Gulp.Orchestrator._emitTaskDone (/home/sergio/proyects/instangular-rest-api/node_modules/orchestrator/index.js:264:8)
    at /home/sergio/proyects/instangular-rest-api/node_modules/orchestrator/index.js:275:23
    at finish (/home/sergio/proyects/instangular-rest-api/node_modules/orchestrator/lib/runTask.js:21:8)
    at DestroyableTransform.<anonymous> (/home/sergio/proyects/instangular-rest-api/node_modules/orchestrator/lib/runTask.js:52:4)
    at DestroyableTransform.f (/home/sergio/proyects/instangular-rest-api/node_modules/once/once.js:17:25)
    at emitOne (events.js:82:20)
    at DestroyableTransform.emit (events.js:169:7)
    at DestroyableTransform.<anonymous> (/home/sergio/proyects/instangular-rest-api/node_modules/gulp-istanbul/index.js:178:12)
    at emitNone (events.js:72:20)
    at DestroyableTransform.emit (events.js:166:7)
    at endReadableNT (/home/sergio/proyects/instangular-rest-api/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:865:12)
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickDomainCallback (node.js:397:17)
[13:58:10] completed !!
npm ERR! Test failed.  See above for more details.

How API Port Change ?

I'm just port change.

I'm change source code in config/env port is 3001.

After All API response is "API Not Found".

even also health check API result is same.

gitignore OS files

Hey, first of all great starter kit.

I've recently started playing with it and its awesome. I looked into the gitignore file and there isn't mentioned any script for ignoring OS specific files. Are PRs welcomed? If you agree this, needs to be added I'd be more than happy to contribute.

Mongoose debug

Add mongoose debug

+if (process.env['MONGOOSE_DEBUG']) {

  • mongoose.set('debug', function (collectionName, method, query, doc) {
  • console.log(
  •  `${collectionName}.${method}`,
    
  •  require('util').inspect(query, false, 20),
    
  •  doc
    
  • )
  • })
    +}

Istanbul issue in Windows

Hi,

When run the test script, I got the same error as here.
I am running under windows (node v5).

Any hint to solve it ?

Error type is always 'Error'

Line 67 of code file ./config/express.js:

const err = new APIError('API not found', httpStatus.NOT_FOUND);

put following code after the above:

console.log(err instanceof APIError); // output false

To my understanding, the output should be true, since err is an instance of APIError?

node version 6.2.0

Thanks,

'gulp serve' not running in Node.js 6.2.2(NPM 3.9.5)

After running 'npm install', I tried to run 'gulp serve'.
I am getting the following error:

[12:57:48] Failed to load external module babel-register
[12:57:48] Failed to load external module babel-core/register
[12:57:48] Failed to load external module babel/register
/Volumes/MACDATA/Current_Work/uslikey/project/express-mongoose-es6-rest-api/gulpfile.babel.js:1
(function (exports, require, module, __filename, __dirname) { import gulp from 'gulp';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Liftoff.handleArguments (/usr/local/lib/node_modules/gulp/bin/gulp.js:116:3)
at Liftoff. (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:193:16)

So I installed 'babel-register', 'babel-core/register' and 'babel/register' by 'npm install' .
After that, when I run 'gulp serve' I faced the following:

[13:15:23] Requiring external module babel-register
module.js:442
throw err;
^

Error: Cannot find module './_baseClone'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object. (/Volumes/MACDATA/Current_Work/uslikey/project/express-mongoose-es6-rest-api/node_modules/babel-plugin-add-module-exports/node_modules/babel-template/node_modules/lodash/cloneDeep.js:1:79)
at Module._compile (module.js:541:32)
at Module._extensions..js (module.js:550:10)
at Object.require.extensions.(anonymous function) as .js
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)

Everything was all right in Node.js 4.4.3

Cant run tests on windows

Running yarn test I am getting an error saying that NODE_ENV is not recognized as a command. The line which is being run: NODE_ENV=test babel-node node_modules/.bin/isparta cover _mocha -- --ui bdd --reporter spec --colors --compilers js:babel-core/register ./server/**/*.test.js

Gulp is starting twice

I don't know whether this is a intended or not but this is quite slow when on development.
*You can produce the same result just by changing /api/health-care response text from OK to anything
Any Solution?

image

I cant serve Any static file

Im have image file in my public folder and added this code but it's not working :
app.use("/public", express.static(path.join(__dirname, '/public')));

App crashes after a fresh install

gulp serve fails.

$ gulp serve
[19:17:41] Requiring external module babel-register
[19:17:42] Using gulpfile ~/tmp_clones/express-mongoose-es6-rest-api/gulpfile.babel.js
[19:17:42] Starting 'clean'...
[19:17:42] Finished 'clean' after 5.76 ms
[19:17:42] Starting 'serve'...
[19:17:42] Starting 'lint'...
[19:17:42] Starting 'copy'...
[19:17:42] Starting 'babel'...
[19:17:42] Finished 'serve' after 132 ms
[19:17:49] Finished 'copy' after 6.81 s
[19:17:50] Finished 'lint' after 8.47 s
[19:17:50] Finished 'babel' after 8.36 s
[19:17:50] Starting 'nodemon'...
[19:17:50] Finished 'nodemon' after 76 ms
[19:17:50] [nodemon] 1.9.2
[19:17:50] [nodemon] to restart at any time, enter `rs`
[19:17:50] [nodemon] watching: *.*
[19:17:50] [nodemon] starting `node dist/index.js`
/Users/user/tmp_clones/express-mongoose-es6-rest-api/node_modules/mongodb/lib/server.js:242
        process.nextTick(function() { throw err; })
                                      ^

Error: unable to connect to database: mongodb://localhost/express-mongoose-es6-rest-api-development
    at NativeConnection.<anonymous> (/Users/user/tmp_clones/express-mongoose-es6-rest-api/dist/index.js:31:8)
    at emitOne (events.js:90:13)
    at NativeConnection.emit (events.js:182:7)
    at NativeConnection.Connection.error (/Users/user/tmp_clones/express-mongoose-es6-rest-api/node_modules/mongoose/lib/connection.js:449:8)
    at /Users/user/tmp_clones/express-mongoose-es6-rest-api/node_modules/mongoose/lib/connection.js:478:15
    at /Users/user/tmp_clones/express-mongoose-es6-rest-api/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:69:21
    at /Users/user/tmp_clones/express-mongoose-es6-rest-api/node_modules/mongodb/lib/db.js:231:14
    at null.<anonymous> (/Users/user/tmp_clones/express-mongoose-es6-rest-api/node_modules/mongodb/lib/server.js:240:9)
    at g (events.js:273:16)
    at emitTwo (events.js:100:13)
    at emit (events.js:185:7)
    at null.<anonymous> (/Users/user/tmp_clones/express-mongoose-es6-rest-api/node_modules/mongodb-core/lib/topologies/server.js:218:12)
    at g (events.js:273:16)
    at emitTwo (events.js:100:13)
    at emit (events.js:185:7)
    at null.<anonymous> (/Users/user/tmp_clones/express-mongoose-es6-rest-api/node_modules/mongodb-core/lib/connection/pool.js:119:12)
    at g (events.js:273:16)
    at emitTwo (events.js:100:13)
    at emit (events.js:185:7)
    at Socket.<anonymous> (/Users/user/tmp_clones/express-mongoose-es6-rest-api/node_modules/mongodb-core/lib/connection/connection.js:151:49)
    at Socket.g (events.js:273:16)
    at emitOne (events.js:90:13)
[19:17:51] [nodemon] app crashed - waiting for file changes before starting...

server error

{"message":"Not Found","stack":"Error: API not found\n at APIError.ExtendableError (d:\Dev\express-mongoose-es6-rest-api-master\server1\dist\server\helpers\APIError.js:35:11)\n at new APIError (d:\Dev\express-mongoose-es6-rest-api-master\server1\dist\server\helpers\APIError.js:63:77)\n at d:\Dev\express-mongoose-es6-rest-api-master\server1\dist\config\express.js:122:13\n at Layer.handle as handle_request\n at trim_prefix (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:312:13)\n at d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:280:7\n at Function.process_params (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:330:12)\n at next (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:271:10)\n at Layer.handle as handle_request\n at trim_prefix (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:312:13)\n at d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:280:7\n at Function.process_params (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:330:12)\n at next (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:271:10)\n at d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express-winston\index.js:291:9\n at Layer.handle as handle_request\n at trim_prefix (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:312:13)\n at d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:280:7\n at Function.process_params (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:330:12)\n at next (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\express\lib\router\index.js:271:10)\n at cors (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\cors\lib\index.js:178:7)\n at d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\cors\lib\index.js:228:17\n at originCallback (d:\Dev\express-mongoose-es6-rest-api-master\server1\node_modules\cors\lib\index.js:217:15)"}

Serving Static Assets Fails

How can I serve static files from current working directory. I have added public folder in root and it doesn't serve

app.use('/static', () => {
  let cwd = path.join(process.cwd());
  let staticfiles = path.resolve(cwd, 'public');
  return express.static(staticfiles);
});

have problem in auth

i find the user's CRUD don't have auth, i hope it have a permission control, so that the administrator can handle the user instead of visitors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.