Start by cloning the repository using: git clone https://github.com/IamRaviTejaG/key-value-store.git
followed by cd key-value-store
.
Install all the dependencies (including the dev dependencies) using the npm install
or npm i
command. Once the dependencies are installed, use npm start
to start the server.
Use an API testing tool like Postman or Insomnia to send/receive HTTP requests.
body-parser
commander
dotenv
express
mongoose
morgan
Developer dependencies:
@babel/cli
@babel/core
(Transpiling ES6 code for use with NodeJS)@babel/present-env
@babel/register
chai
(Assertion)mocha
(Testing)nyc
(Test coverage)request
request-promise
(For sending HTTP requests to the server while testing)rimraf
(The UNIX rm -rf command for Node)standard
(Linting)
The .env
file holds the important variables for the whole application which include the database URL, database port, application port, etc.
Please make sure that the both the index.js
, which is the core app file and store-cli.js
, which is the cli utility file have access to the .env
file. This is important for them to function properly.
The package.json
file contains five scripts for running locally: linter
, test
, coverage
, build
& start
.
"linter": "standard --fix"
Runs the StandardJS linter along with the --fix
flag, which lints code to a great extent. The traceback (if one shows up) is the list of errors that need to be fixed manually.
"test": "mocha --require @babel/register --timeout 5000 --exit"
Runs only the tests.
"coverage": "nyc --reporter=text mocha --require @babel/register --timeout 5000 --exit"
Runs the test coverage & shows up detailed report.
"build": "rimraf dist/ && babel ./ --out-dir dist/ --copy-files"
Builds the project.
"start": "npm run build && node dist/index.js --no-deprecation"
First builds and then starts the server.
To use the CLI, you must make sure that the server is up and running. The steps for successful usage are:
- Open a terminal window, and run
npm start
. This fires up the server. Please keep this terminal window running. - Open another terminal window, and run
node store-cli --help
. This will show a list of commands, which areget
,set
&delete
. - The syntax is:
node store-cli get <key>
node store-cli set <key> <value>
node store-cli delete <key>
URL: /get/:key
Request type: GET
Data parameters: key
URL: /set/:key/:value
Request type: GET
Data parameters: key, value
URL: /set
Request type: POST
Data parameters: {"key": "key", "value": { "sample-object": "true" } }
Headers: {
"Content-type": "application/json"
}
Please note that the Content-type: "application/json"
header is important for the server to understand that the value being passed is an object.
URL: /delete/:key
Request type: GET
Data parameters: key