Giter Site home page Giter Site logo

nodejs-mysql-boilerplate's Introduction

NodeJS MySQL Boilerplate

This app defines a very neat and modular structure to start you next nodejs project.

Using: MySQL, NodeJS, Express, Bookshelf, Knex, Json Web Token(JWT)

Using ES6, with Babel (http://babeljs.io/)

Pre-requisites:

  1. NodeJS (https://nodejs.org/en/)
  2. Globally installed nodemon (https://nodemon.io/)

Steps to run:

git clone [email protected]:raghavgarg1257/nodejs-mysql-boilerplate.git
cd nodejs-mysql-boilerplate
cp env.example .env
nano .env #now edit credentials according to your machine (mandatory for db connection)
npm install

Now to migrate Database

npm install knex -g

# To create the tables
npm run migrate-up

# To drop the tables
npm run migrate-down

Now to start the server

npm start

The app will be started on the mentioned port which will be printed in the console upon starting the server like: http://localhost:8080.

Available routes

-> GET / : (open*) Just show the message
-> POST / : (open*) Another message.

-> GET /users : (open*) Show all the users in the app
-> POST /users [name, phone, email] : (open*) Add new user (generate jwt token)

-> GET /users:id : (protected*) Get the user info by id
-> PUT /users:id [name, phone, email](optional) : (protected*) Update the user info by id
-> DELETE /users:id : (protected*) Delete the user by id

-> GET /users:id/address : (protected*) Show all the address got the user by id
-> POST /users:id/address [line1, line2, state, pincode, landmark] : (protected*) Add new address to the user by id

# guide
open* - means route is un-protected, anyone can access the route
protected* - means a valid jwt token has to be used to access the route in header "Authorization" with value "Bearer {token}"

nodejs-mysql-boilerplate's People

Contributors

raghavgarg1257 avatar snyk-bot avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

nodejs-mysql-boilerplate's Issues

ER_ACCESS_DENIED_ERROR

Hi
I have this problem when running the command: npm run migrate-up

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[email protected] migrate-down /home/namvh/Desktop/nodejs-mysql-boilerplate

DEBUG=knex:tx knex migrate:rollback

Error: ER_ACCESS_DENIED_ERROR: Access denied for user '{db namvh}'@'localhost' (using password: YES)
at Handshake.Sequence._packetToError (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
at Handshake.ErrorPacket (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/mysql/lib/protocol/sequences/Handshake.js:130:18)
at Protocol._parsePacket (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/mysql/lib/protocol/Protocol.js:279:23)
at Parser.write (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket. (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/mysql/lib/Connection.js:103:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:191:7)
at readableAddChunk (_stream_readable.js:178:18)
at Socket.Readable.push (_stream_readable.js:136:10)
at TCP.onread (net.js:561:20)
--------------------
at Protocol._enqueue (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/mysql/lib/protocol/Protocol.js:52:23)
at Connection.connect (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/mysql/lib/Connection.js:130:18)
at /home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/knex/lib/dialects/mysql/index.js:106:18
at Promise._execute (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/bluebird/js/release/debuggability.js:303:9)
at Promise._resolveFromExecutor (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/bluebird/js/release/promise.js:79:10)
at Client_MySQL.acquireRawConnection (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/knex/lib/dialects/mysql/index.js:104:12)
at Object.create (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/knex/lib/client.js:239:16)
at Pool._createResource (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/generic-pool/lib/generic-pool.js:354:17)
at Pool._ensureMinimum (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/generic-pool/lib/generic-pool.js:408:12)
at new Pool (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/generic-pool/lib/generic-pool.js:157:8)
at Client_MySQL.initializePool (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/knex/lib/client.js:269:17)
at Client_MySQL.Client (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/knex/lib/client.js:116:12)
at new Client_MySQL (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/knex/lib/dialects/mysql/index.js:62:20)
at Knex (/home/namvh/Desktop/nodejs-mysql-boilerplate/node_modules/knex/lib/index.js:60:34)

npm ERR! Linux 4.10.0-42-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "migrate-down"
npm ERR! node v7.10.1
npm ERR! npm v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] migrate-down: DEBUG=knex:tx knex migrate:rollback
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] migrate-down script 'DEBUG=knex:tx knex migrate:rollback'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the nodejs-mysql-boilerplate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! DEBUG=knex:tx knex migrate:rollback
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs nodejs-mysql-boilerplate
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls nodejs-mysql-boilerplate
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /root/.npm/_logs/2018-01-10T16_00_57_779Z-debug.log
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
At first I put like this in .env.save file:

\ PORT = 8080

DB = {db server_HHC}
DB_USERNAME = {db root}
DB_PASSWORD = {db abc123!}

JWT_SECRET = anystring

It is also faulty.

I search on google, someone said: add new users to the database.

Next time I try to add new users to the database and try to change

\ PORT = 8080

DB = {db server_HHC}
DB_USERNAME = {db namvh}
DB_PASSWORD = {db abc456!}

JWT_SECRET = anystring

But it still fails as above.

Can you help me fix this problem?

thank you very much.

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.