Coder Social home page Coder Social logo

node-express-realworld-example-app's Introduction

Node/Express/Prisma Example App

Build Status

Example Node (Express + Prisma) codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld API spec.

Getting Started

Prerequisites

Run the following command to install dependencies:

npm install

Environment variables

This project depends on some environment variables. If you are running this project locally, create a .env file at the root for these variables. Your host provider should included a feature to set them there directly to avoid exposing them.

Here are the required ones:

DATABASE_URL=
JWT_SECRET=
NODE_ENV=production

Generate your Prisma client

Run the following command to generate the Prisma Client which will include types based on your database schema:

npx prisma generate

Apply any SQL migration script

Run the following command to create/update your database based on existing sql migration scripts:

npx prisma migrate deploy

Run the project

Run the following command to run the project:

npx nx serve api

Seed the database

The project includes a seed script to populate the database:

npx prisma db seed

Deploy on a remote server

Run the following command to:

  • install dependencies
  • apply any new migration sql scripts
  • run the server
npm ci && npx prisma migrate deploy && node dist/api/main.js

node-express-realworld-example-app's People

Contributors

agenestar avatar akarandi avatar anishkny avatar apai4 avatar deksden avatar ericsimons avatar geromegrignon avatar hum4n01d avatar jibolash avatar mordorreal avatar ryanjcruz avatar yukichikawada 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

node-express-realworld-example-app's Issues

adding social authentications to passport js.

Hi everyone.
How would be the best way to integrate social auth to passportjs ?
I have tried doing so, for facebook, I have created a new app, set everything up, the GET router gets a 404 response.

Unknown modifier: $pushAll

Hi,

I am using Ruby on Rails with Heroku. My code working till mongo DB version 3.4. Now mLab has upgraded mongoDB version from 3.4 to 3.6.

I am getting Cannot read property 'username' of undefined

Hi

This codebase looks really good thanks for providing it, I am a beginner to express environment. /api/users is this error something related to Router, bodyParser ? or something else ? help on this would be appreciated.

In console it morgan an error 500

screen shot 2017-01-27 at 7 15 36 pm

bug in user model

follow method on user mongoose model is implemented incorrectly (models/User.js) line: 78

UserSchema.methods.follow = function(id){
  if(this.favorites.indexOf(id) === -1){ // this is wrong it should be this.following.indexOf(id)
    this.following.push(id);
  }

  return this.save();
};

the first line of the function is wrong, it should be:

if (this.following.indexOf(id) === -1)

cannot start the app on glitch

Hi.
I pushed the button to run this app on glitch.
I see the following errors on the console.
Could you tell me how to solve this problem?
I'd appreciate your advice.

at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)

Emitted 'error' event at:

    at NativeConnection.Connection.error (/app/node_modules/mongoose/lib/connection.js:443:8)

    at /app/node_modules/mongoose/lib/connection.js:472:15

    at /app/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:21

    at /app/node_modules/mongodb/lib/db.js:232:14

    at Server.<anonymous> (/app/node_modules/mongodb/lib/server.js:240:9)

    at Object.onceWrapper (events.js:277:13)

    at Server.emit (events.js:189:13)

    at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:308:68)

    at Pool.emit (events.js:189:13)

    at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:115:12)

    at Object.onceWrapper (events.js:277:13)

    at Connection.emit (events.js:189:13)

    at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:144:49)

    at Object.onceWrapper (events.js:277:13)

    at Socket.emit (events.js:189:13)

    at emitErrorNT (internal/streams/destroy.js:82:8)


Could not find node null, using 10


Listening on port 3000


/app/node_modules/mongodb/lib/server.js:242

        process.nextTick(function() { throw err; })

                                      ^

Error: connect ECONNREFUSED 127.0.0.1:27017

    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)

Emitted 'error' event at:

    at NativeConnection.Connection.error (/app/node_modules/mongoose/lib/connection.js:443:8)

    at /app/node_modules/mongoose/lib/connection.js:472:15

    at /app/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:21

    at /app/node_modules/mongodb/lib/db.js:232:14

    at Server.<anonymous> (/app/node_modules/mongodb/lib/server.js:240:9)

    at Object.onceWrapper (events.js:277:13)

    at Server.emit (events.js:189:13)

    at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:308:68)

    at Pool.emit (events.js:189:13)

    at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:115:12)

    at Object.onceWrapper (events.js:277:13)

    at Connection.emit (events.js:189:13)

    at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:144:49)

    at Object.onceWrapper (events.js:277:13)

    at Socket.emit (events.js:189:13)

    at emitErrorNT (internal/streams/destroy.js:82:8)


Could not find node null, using 10


Listening on port 3000


/app/node_modules/mongodb/lib/server.js:242

        process.nextTick(function() { throw err; })

                                      ^

Error: connect ECONNREFUSED 127.0.0.1:27017

    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)

Emitted 'error' event at:

    at NativeConnection.Connection.error (/app/node_modules/mongoose/lib/connection.js:443:8)

    at /app/node_modules/mongoose/lib/connection.js:472:15

    at /app/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:21

    at /app/node_modules/mongodb/lib/db.js:232:14

    at Server.<anonymous> (/app/node_modules/mongodb/lib/server.js:240:9)

    at Object.onceWrapper (events.js:277:13)

    at Server.emit (events.js:189:13)

    at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:308:68)

    at Pool.emit (events.js:189:13)

    at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:115:12)

    at Object.onceWrapper (events.js:277:13)

    at Connection.emit (events.js:189:13)

    at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:144:49)

    at Object.onceWrapper (events.js:277:13)

    at Socket.emit (events.js:189:13)

    at emitErrorNT (internal/streams/destroy.js:82:8)


Could not find node null, using 10


Listening on port 3000


/app/node_modules/mongodb/lib/server.js:242

        process.nextTick(function() { throw err; })

                                      ^

Error: connect ECONNREFUSED 127.0.0.1:27017

    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)

Emitted 'error' event at:

    at NativeConnection.Connection.error (/app/node_modules/mongoose/lib/connection.js:443:8)

    at /app/node_modules/mongoose/lib/connection.js:472:15

    at /app/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:21

    at /app/node_modules/mongodb/lib/db.js:232:14

    at Server.<anonymous> (/app/node_modules/mongodb/lib/server.js:240:9)

    at Object.onceWrapper (events.js:277:13)

    at Server.emit (events.js:189:13)

    at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:308:68)

    at Pool.emit (events.js:189:13)

    at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:115:12)

    at Object.onceWrapper (events.js:277:13)

    at Connection.emit (events.js:189:13)

    at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:144:49)

    at Object.onceWrapper (events.js:277:13)

    at Socket.emit (events.js:189:13)

    at emitErrorNT (internal/streams/destroy.js:82:8)


Could not find node null, using 10


Listening on port 3000


/app/node_modules/mongodb/lib/server.js:242

        process.nextTick(function() { throw err; })

                                      ^

Error: connect ECONNREFUSED 127.0.0.1:27017

    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)

Emitted 'error' event at:

    at NativeConnection.Connection.error (/app/node_modules/mongoose/lib/connection.js:443:8)

    at /app/node_modules/mongoose/lib/connection.js:472:15

    at /app/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:21

    at /app/node_modules/mongodb/lib/db.js:232:14

    at Server.<anonymous> (/app/node_modules/mongodb/lib/server.js:240:9)

    at Object.onceWrapper (events.js:277:13)

    at Server.emit (events.js:189:13)

    at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:308:68)

    at Pool.emit (events.js:189:13)

    at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:115:12)

    at Object.onceWrapper (events.js:277:13)

    at Connection.emit (events.js:189:13)

    at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:144:49)

    at Object.onceWrapper (events.js:277:13)

    at Socket.emit (events.js:189:13)

    at emitErrorNT (internal/streams/destroy.js:82:8)


Could not find node null, using 10


Listening on port 3000


/app/node_modules/mongodb/lib/server.js:242

        process.nextTick(function() { throw err; })

                                      ^

Error: connect ECONNREFUSED 127.0.0.1:27017

    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)

Emitted 'error' event at:

    at NativeConnection.Connection.error (/app/node_modules/mongoose/lib/connection.js:443:8)

    at /app/node_modules/mongoose/lib/connection.js:472:15

    at /app/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:21

    at /app/node_modules/mongodb/lib/db.js:232:14

    at Server.<anonymous> (/app/node_modules/mongodb/lib/server.js:240:9)

    at Object.onceWrapper (events.js:277:13)

    at Server.emit (events.js:189:13)

    at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:308:68)

    at Pool.emit (events.js:189:13)

    at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:115:12)

    at Object.onceWrapper (events.js:277:13)

    at Connection.emit (events.js:189:13)

    at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:144:49)

    at Object.onceWrapper (events.js:277:13)

    at Socket.emit (events.js:189:13)

    at emitErrorNT (internal/streams/destroy.js:82:8)

Deprecated dependencies

npm install

npm WARN deprecated [email protected]: Use uuid module instead
npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN deprecated [email protected]: Please upgrade to 2.2.19 or higher

Thanks @pgbonino for reporting

We should also enable CI and Greenkeeper for this repo to ensure freshness

preload data?

Hey folks! Any ideas on how to load the database with mock data?

Nodemon dependency in package.js

instructions are npm install && npm run dev but npm run dev runs nodemon ./app.s. nodemon isn't a dependency or dev dependency in package.json, so it's not installed or defined.

Id cast error deleting comment

When I try to send a delete request to remove a comment, specifying an id (integer number), I get the error

Cast to ObjectId failed for value "1" at path "_id" for model "Comment"

I think that's because the model Comment does not specify an id type, so mongoose create a default one.
Am I missing something?

Tags are not saved on server

Tags are slightly broken: can not add any new tag, or update article to add tag.

Tested with React frontend.

Adding tag to database manually will do the trick - tag appears. Try to digg a little bit

update: correction - tags are saved for new post, but you should press Enter for tag edit filed to add tag. If you do not press enter, tag in edit field does not added to post. This is separate UI issue, will post in other repo.

But updating article with new tags did not work.

req.body empty on user register route(post /users)

I am using following settings with body-parser package( v1.15.0 ) and not able to get req.body value. What can be the reason? I am using postman to make the POST request where the body is of application/json type.

image

image

Routing doesn't work anymore

When running npm install & npm run dev, no routes work as there's always an 404 error, no matter what route I try to open. 2 months ago this issue wasn't there.

Example:

Error: Not Found
    at D:\patenprogramm-backend\app.js:58:13
    at Layer.handle [as handle_request] (D:\patenprogramm-backend\node_modules\e
xpress\lib\router\layer.js:95:5)
    at trim_prefix (D:\patenprogramm-backend\node_modules\express\lib\router\ind
ex.js:312:13)
    at D:\patenprogramm-backend\node_modules\express\lib\router\index.js:280:7
    at Function.process_params (D:\patenprogramm-backend\node_modules\express\li
b\router\index.js:330:12)
    at next (D:\patenprogramm-backend\node_modules\express\lib\router\index.js:2
71:10)
    at D:\patenprogramm-backend\node_modules\express\lib\router\index.js:618:15
    at next (D:\patenprogramm-backend\node_modules\express\lib\router\index.js:2
56:14)
    at Function.handle (D:\patenprogramm-backend\node_modules\express\lib\router
\index.js:176:3)
    at router (D:\patenprogramm-backend\node_modules\express\lib\router\index.js
:46:12)
    at Layer.handle [as handle_request] (D:\patenprogramm-backend\node_modules\e
xpress\lib\router\layer.js:95:5)
    at trim_prefix (D:\patenprogramm-backend\node_modules\express\lib\router\ind
ex.js:312:13)
    at D:\patenprogramm-backend\node_modules\express\lib\router\index.js:280:7
    at Function.process_params (D:\patenprogramm-backend\node_modules\express\li
b\router\index.js:330:12)
    at next (D:\patenprogramm-backend\node_modules\express\lib\router\index.js:2
71:10)
    at Layer.handle [as handle_request] (D:\patenprogramm-backend\node_modules\e
xpress\lib\router\layer.js:91:12)

Does anyone here have the same problem and knows how to fix it? This is also happening for my app based on this repo, but as it happens with the current repo, I don't know what the problem is.

Follow feature does not work properly on article pages

ArticleActions.vue.

computed:
스크린샷 2019-11-25 오전 10 58 49
methods:
스크린샷 2019-11-25 오전 10 59 10

  • When the toggle button is clicked twice, the method works but the text of the toggle button does not change.
  • Following on the article page indicates that all users of other posts are followed.

When loading the article page for the first time, only User, Comments, and Article are set, but the change is the profile, so it does not bring follow results when loading.

This could be solved by loading setProfile, but I hope there's a better way to make it load longer.

Refactoring code.

This code can be refactored

if(isProduction){
  mongoose.connect(process.env.MONGODB_URI);
} else {
  mongoose.connect('mongodb://localhost/conduit');
  mongoose.set('debug', true);
}

With the help of the variable isProduction.

  mongoose.connect(process.env.MONGODB_URI);
  mongoose.set('debug',!isProduction);

bugs

I found two bugs and made corrections. if I am wrong, please point out:

api/articles.js file:

`// update article
router.put('/:article', auth.required, function(req, res, next) {
User.findById(req.payload.id).then(function(user){ //added code
//if(req.article._id.toString() === req.payload.id.toString()){ //original code
if(req.article.author._id.toString() === req.payload.id.toString()){ //modified code
if(typeof req.body.article.title !== 'undefined'){
req.article.title = req.body.article.title;
}

  if(typeof req.body.article.description !== 'undefined'){
    req.article.description = req.body.article.description;
  }

  if(typeof req.body.article.body !== 'undefined'){
    req.article.body = req.body.article.body;
  }

  req.article.save().then(function(article){
    return res.json({article: article.toJSONFor(user)});
  }).catch(next);
} else {
  return res.send(403);
}

}); //added codes
});

// delete article
router.delete('/:article', auth.required, function(req, res, next) {
//User.findById(req.payload.id).then(function(){ //original codes
//if(req.article.author.toString() === req.payload.id.toString()){ //original code
if(req.article.author._id.toString() === req.payload.id.toString()){ //modified code
return req.article.remove().then(function(){
return res.sendStatus(204);
});
} else {
return res.sendStatus(403);
}
//}); //original code
});`

Unfinished sentence in Readme

Under "Application Structure" -> routes/ there is an unfinished sentence. It's unclear whether this was intended to be finished, or should be removed.

routes/ - This folder contains the route definitions for our API. They contain

Ideas for unit testing?

This may be a little out-of-band for the kind of issues you're looking for, but I was just wondering whether you have any tips on what I could unit test in this repo (for my workshop). Looking through things, there's not a whole lot of logic. It's mostly configuring things. I'm unsure whether there would be any value in unit tests (though Integration and E2E tests would definitely be valuable here). Do you think there's any useful business logic in here that we could test?

Also I'm planning on demonstrating TDD, so if you have any ideas of a feature I could add or a bug I could create and then fix with TDD, that'd be helpful! Thanks!

I am getting "Cannot read property 'username' of undefined"

Hi

This codebase looks really good thanks for providing it, I am a beginner to express environment. /api/users is this error something related to Router, bodyParser ? or something else ? help on this would be appreciated.

In console morgan throws an error 500

screen shot 2017-01-27 at 7 15 36 pm

Most of the tests fail

I'm not familiar with newman, so no idea how to debug this, there is just two json files, where is the code?

/tmp $ git clone https://github.com/gothinkster/node-express-realworld-example-app
Cloning into 'node-express-realworld-example-app'...
remote: Counting objects: 250, done.
remote: Total 250 (delta 0), reused 0 (delta 0), pack-reused 250
Receiving objects: 100% (250/250), 127.33 KiB | 149.00 KiB/s, done.
Resolving deltas: 100% (116/116), done.
/tmp $ cd node-express-realworld-example-app/
/tmp/node-express-realworld-example-app $ npm install
npm WARN deprecated [email protected]: Critical security bugs fixed in 2.5.5
npm WARN deprecated [email protected]: Use uuid module instead
npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN deprecated [email protected]: Please upgrade to 2.2.19 or higher

> [email protected] install /private/tmp/node-express-realworld-example-app/node_modules/fsevents
> node install

[fsevents] Success: "/private/tmp/node-express-realworld-example-app/node_modules/fsevents/lib/binding/Release/node-v59-darwin-x64/fse.node" is installed via remote

> [email protected] postinstall /private/tmp/node-express-realworld-example-app/node_modules/nodemon
> node bin/postinstall || exit 0

npm notice created a lockfile as package-lock.json. You should commit this file.
added 653 packages in 31.609s
/tmp/node-express-realworld-example-app $ npm test

> [email protected] test /private/tmp/node-express-realworld-example-app
> newman run ./tests/api-tests.postman.json -e ./tests/env-api-tests.postman.json

newman

Conduit API Tests

❏ Auth
↳ Register
  POST http://localhost:3000/api/users   2⠄ JSONError in test-script

↳ Login
  POST http://localhost:3000/api/users/login   4⠄ JSONError in test-script

↳ Login and Remember Token
  POST http://localhost:3000/api/users/login   6⠄ JSONError in test-script

↳ Current User
  GET http://localhost:3000/api/user   8⠄ JSONError in test-script

↳ Update User
  PUT http://localhost:3000/api/user  10⠄ JSONError in test-script

❏ Articles with authentication
↳ Feed
  GET http://localhost:3000/api/articles/feed  12. Response code is 200 OK

↳ All Articles
  GET http://localhost:3000/api/articles  14. Response code is 200 OK

↳ All Articles with auth
  GET http://localhost:3000/api/articles  16. Response code is 200 OK

↳ Articles by Author
  GET http://localhost:3000/api/articles?author=johnjacob  18. Response code is 200 OK

↳ Articles by Author with auth
  GET http://localhost:3000/api/articles?author=johnjacob  20. Response code is 200 OK

↳ Articles Favorited by Username
  GET http://localhost:3000/api/articles?favorited=jane  22. Response code is 200 OK

↳ Articles Favorited by Username with auth
  GET http://localhost:3000/api/articles?favorited=jane  24. Response code is 200 OK

↳ Articles by Tag
  GET http://localhost:3000/api/articles?tag=dragons  26. Response code is 200 OK

↳ Create Article
  POST http://localhost:3000/api/articles  28⠄ JSONError in test-script

↳ Single Article by slug
  GET http://localhost:3000/api/articles/{{slug}}  30⠄ JSONError in test-script

↳ Update Article
  PUT http://localhost:3000/api/articles/{{slug}}  32⠄ JSONError in test-script

↳ Favorite Article
  POST http://localhost:3000/api/articles/{{slug}}/favorite  34⠄ JSONError in test-script

↳ Unfavorite Article
  DELETE http://localhost:3000/api/articles/{{slug}}/favorite  36⠄ JSONError in test-script

❏ Articles
↳ All Articles
  GET http://localhost:3000/api/articles  38. Response code is 200 OK

↳ Articles by Author
  GET http://localhost:3000/api/articles?author=johnjacob  40. Response code is 200 OK

↳ Articles Favorited by Username
  GET http://localhost:3000/api/articles?favorited=jane  42. Response code is 200 OK

↳ Articles by Tag
  GET http://localhost:3000/api/articles?tag=dragons  44. Response code is 200 OK

↳ Single Article by slug
  GET http://localhost:3000/api/articles/{{slug}}  46⠄ JSONError in test-script

❏ Comments
↳ All Comments for Article
  GET http://localhost:3000/api/articles/{{slug}}/comments  48. Response code is 200 OK

↳ Create Comment for Article
  POST http://localhost:3000/api/articles/{{slug}}/comments  50⠄ JSONError in test-script

↳ Delete Comment for Article
  DELETE http://localhost:3000/api/articles/{{slug}}/comments/1
❏ Profiles
↳ Profile
  GET http://localhost:3000/api/profiles/johnjacob  53. Response code is 200 OK

↳ Follow Profile
  POST http://localhost:3000/api/profiles/johnjacob/follow  55. Response code is 200 OK

↳ Unfollow Profile
  DELETE http://localhost:3000/api/profiles/johnjacob/follow  57. Response code is 200 OK

❏ Tags
↳ All Tags
  GET http://localhost:3000/api/tags  59. Response code is 200 OK

❏ Cleanup
↳ Delete Article
  DELETE http://localhost:3000/api/articles/{{slug}}
┌─────────────────────────┬──────────┬──────────┐
│                         │ executed │   failed │
├─────────────────────────┼──────────┼──────────┤
│              iterations │        1 │        0 │
├─────────────────────────┼──────────┼──────────┤
│                requests │       31 │       31 │
├─────────────────────────┼──────────┼──────────┤
│            test-scripts │       29 │       12 │
├─────────────────────────┼──────────┼──────────┤
│      prerequest-scripts │        0 │        0 │
├─────────────────────────┼──────────┼──────────┤
│              assertions │       17 │       17 │
├─────────────────────────┴──────────┴──────────┤
│ total run duration: 772ms                     │
├───────────────────────────────────────────────┤
│ total data received: 0B (approx)              │
├───────────────────────────────────────────────┤
│ average response time: 0ms                    │
└───────────────────────────────────────────────┘

   #  failure                    detail

 01.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Register"

 02.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Register"

 03.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Login"

 04.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Login"

 05.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Login and Remember Token"

 06.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Login and Remember Token"

 07.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Current User"

 08.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Current User"

 09.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Auth / Update User"

 10.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Auth / Update User"

 11.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Feed"

 12.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Feed"

 13.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / All Articles"

 14.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / All Articles"

 15.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / All Articles with auth"

 16.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / All Articles with auth"

 17.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles by Author"

 18.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles by Author"

 19.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles by Author with auth"

 20.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles by Author with auth"

 21.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles Favorited by Username"

 22.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles Favorited by Username"

 23.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles Favorited by Username with auth"

 24.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles Favorited by Username with auth"

 25.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Articles by Tag"

 26.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles with authentication / Articles by Tag"

 27.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Create Article"

 28.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Create Article"

 29.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Single Article by slug"

 30.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Single Article by slug"

 31.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Update Article"

 32.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Update Article"

 33.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Favorite Article"

 34.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Favorite Article"

 35.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles with authentication / Unfavorite Article"

 36.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles with authentication / Unfavorite Article"

 37.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / All Articles"

 38.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles / All Articles"

 39.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / Articles by Author"

 40.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles / Articles by Author"

 41.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / Articles Favorited by Username"

 42.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles / Articles Favorited by Username"

 43.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / Articles by Tag"

 44.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Articles / Articles by Tag"

 45.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Articles / Single Article by slug"

 46.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Articles / Single Article by slug"

 47.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Comments / All Comments for Article"

 48.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Comments / All Comments for Article"

 49.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Comments / Create Comment for Article"

 50.  JSONError                  Unexpected token u in JSON at position 0
                                 at test-script
                                 inside "Comments / Create Comment for Article"

 51.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Comments / Delete Comment for Article"

 52.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Profiles / Profile"

 53.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Profiles / Profile"

 54.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Profiles / Follow Profile"

 55.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Profiles / Follow Profile"

 56.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Profiles / Unfollow Profile"

 57.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Profiles / Unfollow Profile"

 58.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Tags / All Tags"

 59.  AssertionError             Response code is 200 OK
                                 expected false to be truthy
                                 at assertion:0 in test-script
                                 inside "Tags / All Tags"

 60.  Error                      connect ECONNREFUSED 127.0.0.1:3000
                                 at request
                                 inside "Cleanup / Delete Article"
npm ERR! Test failed.  See above for more details.
/tmp/node-express-realworld-example-app $ node -v
v9.2.0

Route.get() requires callback functions but got a [object Undefined]

I am attempting to recreate this application from scratch. So far I have users controller in place (without the articles, profiles and tags controllers.

However when I try to run the server, I get Route.get() requires callback functions but got a [object Undefined] error. If I comment out the router.get('/user' and router.put('/user' routes, everything works okay and I can register users without problem.

I have been on this for hours. please does anyone know what the problem might be and how to fix it?

Here is complete error message:

C:\production apps\backend\node_modules\express\lib\router\route.js:202
        throw new Error(msg);
        ^
Error: Route.get() requires callback functions but got a [object Undefined]
    at Route.(anonymous function) [as get] (C:\production apps\backend\node_modules\express\lib\router\route.js:202:15)
    at Function.proto.(anonymous function) [as get] (C:\production apps\backend\node_modules\express\lib\router\index.js:510:19)
    at Object.<anonymous> (C:\production apps\backend\routes\api\users.js:9:8)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\production apps\backend\routes\api\index.js:3:17)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node ./app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\BenKay\AppData\Roaming\npm-cache\_logs\2017-09-07T13_43_52_191Z-debug.log

Unable to follow other users

Not sure why, but this backend is unable to support following other users.

No authorization token was found","error"

PUT / DELETE ARTICLE

Hello,

I am following your angular training. Thanks a lot for your great work !

the app is working perfectly while using your API. I decided to include the node-express-realworld backend. Everything is working well except PUT and DELETE articles methods. I get a 403 Forbidden response. I can delete comments and favorites.

I am new to node and express. I send hours trying to figure out that, without success.

Thanks
Boris

Not able to configure this node backend.

Hello,

I tried to configure this backend, but when i run frontend for each backend call

Request URL:http://localhost:3000/users
Request Method:POST
Status Code:404 Not Found
Remote Address:[::1]:3000
Referrer Policy:no-referrer-when-downgrade

this is i saw at chrome console.

Response:

{"errors":{"message":"Not Found","error":{"status":404}}}

Can anyone help me how to I fix this?

Thanks,

why use passport-js?

I see you are not using passport-js as middleware then why use it at all. also why not use passport-jwt strategy?

when ever i try to signup this happened

username: 'asad32', email: '[email protected]', salt: '90b1efe306255473f9202c1e716d1fd0', hash: '26f80973758c567f86e652380823eab4837147cc9f395130923dcdde416a80d998144d37a9f072a7279a696d1f1488aaf7df887574d0ac4358c52ba45492f0c1c0f84bad3d456452df5400e44fc756494fca0639ca96a08d20aad26d321f85c193a7ae32f167f5b0a6f527894ceb72551664c956355e1947aa8576538b9c0429053a5b067346e07bc05d1b25d44b9679c26beb0d459450b410df4d7922c4049f68b153437b736677748155d87491e0efea0c515ded53225fe3a83d682f7368314dff6b3d0148a855083376e574d038733101a36b7e651245ca3674b9dc5b8728d90ade04c548bbe01d1a2f424d2010c78f948095fed64ef3ef283534a137e78c53588fe3f78429cf1f38695b29767da0cea08328813a2aae4536e6687efb44f9e0f5a86d26fecb7a8ce38f9a0fb79b952dc5f15650c46869dfced75c2de03559d5259eb67458aff5b2cab846ccf7dc0312e044e98b93555d873ce398bc79e3b0994d1c55185e9c4e15ec066f06d88434027a726475ee528840525c8ea72873c414f6e2ef636b1170c710b0fb61423f7cf4d049a50d7cd15232e7d13ba483fdc9cb52d3f7edfd2576e89f25bbbe5805b038423b003bc96e3a4a99c2388d18a5dae4c48c036765c2b83f8ab4a40e82f79545d4f8b7bb53f1b4bcc19f64b3bb2468554f852b2f61bd01ea82d1591a2c1698edb1f27af0c455cec10e5e3904480024', createdAt: new Date("Wed, 11 Sep 2019 08:15:23 GMT"), updatedAt: new Date("Wed, 11 Sep 2019 08:15:23 GMT"), __v: 0 }, { session: null })
C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongoose\lib\utils.js:586
throw err;
^

TypeError: respond is not a function
at C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongoose-unique-validator\index.js:108:29
at C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongoose\lib\utils.js:581:16
at result (C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongodb\lib\operations\execute_operation.js:75:17)
at session.endSession (C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongodb\lib\operations\execute_operation.js:64:11)
at ClientSession.endSession (C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongodb\lib\core\sessions.js:135:41)
at executeCallback (C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongodb\lib\operations\execute_operation.js:59:17)
at callbackWithRetry (C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongodb\lib\operations\execute_operation.js:131:14)
at executeCommand (C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongodb\lib\operations\estimated_document_count.js:47:7)
at server.command (C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongodb\lib\operations\command_v2.js:96:7)
at C:\Users\Asad\Documents\re\node-express-realworld-example-app\node_modules\mongodb\lib\core\connection\pool.js:420:18
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: node ./app.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Asad\AppData\Roaming\npm-cache_logs\2019-09-11T08_15_24_001Z-debug.lo

adding unit tests?

adding tests cases would be beneficial since it will help developers the proper way of doing this?

Error: Not Found at app.js:49:13

I cloned and followed the instruction but encountered the error. The same goes for glitch.com instance. Do I have to have any database in the MongoDb installation?

Where to store the jwt token?

Hey guys, I am new to node and I am very interested in this repo.
I do not quite understand where do we store the jwt token on client side (assign it to a variable? store it in sessonStorage? store it in a cookie? The first two options seem to be a security hole though) so that afterwards it can be sent in other requests to authenticate users.
In the endpoint of POST /users/login the code does this:

passport.authenticate('local', {session: false}, function(err, user, info){
    if(err){ return next(err); }
    if(user){
      user.token = user.generateJWT();
      return res.json({user: user.toAuthJSON()});
    } else {
      return res.status(422).json(info);
    }
  })(req, res, next);

If I understand it correctly, the token only reside in the response. I do not see any frontend code in this repo that calls the this endpoint and uses this token as a http request header.
Can anyone help me with this? Thanks.

How yo upload dile with autentication

Hello

I need some example to upload file.
I do understand how to pass a file in the json body.

I am not be able to configure "multer".

Can you gide me?

Thanks

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.