A boilerplate for Node.js, MongoDB & GraphQL applications.
💡 ES6 code
I started this project to simplify and make it ease of use. I also tried to make it as generic and reusable as possible to cover most use cases of GraphQL apps, without being too specific.
- Local Authentication using Email and Password
- MVC Project Structure
- GraphQL Mutations, Queries, Resolvers
- Account Management
- Register
- Login
- Update profile
- Profile Details
- Add user address
- Update Address
- Remove Address
- Cron job scheduler
- JSON Web Token (JWT) Sign in
- MongoDB
- Node.js 6.0+
- Command Line Tools
- Mac OS X: Xcode (or OS X 10.9+:
xcode-select --install
) - Windows: Visual Studio
- Ubuntu / Linux Mint:
sudo apt-get install build-essential
- Fedora:
sudo dnf groupinstall "Development Tools"
- OpenSUSE:
sudo zypper install --type pattern devel_basis
The easiest way to get started is to clone the repository:
# Get the latest snapshot
git clone --depth=1 https://github.com/ailoitte/node-mongodb-graphql-starter.git myproject
# Change directory
cd myproject
# Install NPM dependencies
npm install
# Then simply start your app
node app.js
Note: I highly recommend installing Nodemon.
It watches for any changes in your node.js app and automatically restarts the
server. Once installed, instead of node app.js
use nodemon app.js
. It will
save you a lot of time in the long run, because you won't need to manually
restart the server each time you make a small change in code. To install, run
sudo npm install -g nodemon
.
Package | Description |
---|---|
async | Utility library that provides asynchronous control flow. |
bcrypt-nodejs | Library for hashing and salting user passwords. |
connect-mongo | MongoDB session store for Express. |
dotenv | Loads environment variables from .env file. |
express | Node.js web framework. |
body-parser | Express 4 middleware. |
morgan | Express 4 middleware. |
mongoose | MongoDB ODM. |
nodemailer | Node.js library for sending emails. |
request | Simplified HTTP request library. |
lodash | Handy JavaScript utilities library. |
validator | Used in conjunction with express-validator. |
jsonwebtoken | An implementation of JSON Web Tokens. |
mongoose-paginate | MongoDB mongoose pagination |
moment | JS date library- parsing,validating,manipulating,andformatting dates. |
mime | Comprehensive MIME type mapping API based on mime-db module. |
firebase-admin | Push notification |
aws-sdk | AWS client SDK |
multer-s3 | Upload multipart to S3 |
winston | async logging library |
cron | Cron job |
mutation {
addUser(name: "Sunil Kumar", email: "[email protected]", mobileNumber:"8867371492", password: "123567"){
id
name
email
mobileNumber
}
}
mutation {
updateUser(name: "Ravi Sanker"){
id
name
email
mobileNumber
}
}
mutation {
loginUser(mobileNumber: "8867371492", password:"1234567") {
id
token
name
email
}
}
mutation {
addUserAddress(street: ["s1", "s2"],
city:"Dehradun",
countryId: "IN",
addressType: "home",
postcode:"23455"
) {
id
street
city
countryId
landmark
locality
addressType
postcode
}
}
mutation {
updateUserAddress(id: "59e4d803d3528728b99b3c53",
street: ["Nesh", "Indra Road"],
city:"Dehradun",
countryId: "IN",
addressType: "home",
postcode:"234551"
) {
id
street
city
countryId
landmark
locality
addressType
postcode
}
}
mutation {
deleteUserAddress(
id: "59e4dc6b875e8829539b20d7"
){
message
}
}
query {
me{
address{
street
city
}
}
}
query {
userAddress(id: "59e4d803d3528728b99b3c53"){
id
city
street
countryId
}
}
}