Slate API docs can be found at http://keatinganthony.com/slate.
Fork the repo.
We're going to be using postgres. If you prefer to use another DB, make sure sequelize supports it as a dialect. Make all necessary changes in
create-node-app/lib/config/config.json
.
- PostgreSQL - Download
We also want to be able to use es6, es7 and beyond. Make sure you have at least Node V8.0.0, which comes with NPM V5.
- Node - Download
Install the dependencies.
npm install
Make sure that you can connect to your DB before proceeding.
- PostgreSQL - Tutorial for mac
- PostgreSQL - Tutorial for linux
Create and migrate development and test databases.
bash create-db.sh // Creates databases
bash migrate-db.sh // Migrates databases
If for some reason you need to start fresh, go ahead and run
bash drop-db.sh // Drops databases
Make sure everything is running smoothly.
npm start // Creates a node_modules folder and installs all packages in packages.json
We have two examples in create-node-app/lib/migrations
. Two files create an initial model, one is changing a already existing column and another is creating a new column for a model.
Some documentation for what you will be working with.
Let's test our endpoints.
npm test
Let's go over the create user endpoint; this will either create or get a user, if it already exists. What does this test for?
The response should be successful.
it("should not return an error", () => {
should.not.exist(error);
});
The response should contain the correct status code.
it("should return a 200 code", () => {
result.should.have.status(200);
});
The response should let us know a new entry was made.
it("should have created a new entry", () => {
result.body.created.should.equal(true);
});
The response should contain the user's ID.
it("should return the user's id", () => {
result.body.id.should.be.a('number');
});
We want to write tests that make sure the endpoints we create are responding with expected behavior. We can even write tests first and then write code to make it pass (TDD)!
- Express - The framework used
- Sequelize - promised based ORM and migration manager
- Mocha - testing framework
- Chai - assertion library
Node, NPM and postgres mentioned above.
If you would like to add or amend anything, please feel free to make a pull request.
- Anthony Keating
contributors who participated in this project.
This project is licensed under the MIT License.
- The open source community