Simple Node.js bootstrap with Express and ES6 / ES2015.
This is the backend version of the Angular bootstrap that I made. Something to guide you out when creating your backend and not sure how to do it. It's simple as the title says and it's mostly a recollection of things that I've learned and seen to be useful.
- Install Node.js and nvm if you don't have them by now. Newest versions suit very well. I used 6.3.1 Node version making this but all versions from >4.0.0 should work. Basically it should work if you write
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash
to your terminal. Thennvm install <node-version>
and if you have already Node installednvm use <node-version>
. - Clone this repository and go to the root and enter
npm i
ornpm install
. - This app uses dotenv for storing environment variables, copy the
.dev-env
file in the root of this folder and name it to.env
e.g.cp .dev-env .env
. If you want to use Travis or Heroku remember to add your variables to their config. Or for your own server create your own production.env
. - This app uses MongoDB as database so you need to either install MongoDB locally or use mlab. I recommend mlab for its easy of use.
- For better development experience it's recommended to use Postman for generating requests to your app. Here's a link to Chrome plugin. For making requests you should set your content-type to application/json and if you have authentication enabled remember to add X-Access-Token -header with valid token.
- Now you're all set, enter
npm start
to run the development server. - Go to localhost:3332 if you want to see the backend running. Not much to look at though.
npm i <library> --S
ornpm i <library> --D
(-S
equals--save
and-D
--save-dev
)npm test
npm run lint
ornpm run lint:fix
npm run db reset
for resetting database, other usable commandsdb add, db destroy, db dump
This app uses basic MVC with services as global helpers. Feel free to make changes and create better solutions. I was going to add option to use postgres but eh maybe later. Also sorry about the very sad test suite.
To disable authentication you can comment out router.use("", auth.authenticate);
and router.use("", auth.onlyAdmin);
in config/routes.js
.