ℹ️User guide: node-mongo setup, installation and usage
NODE-MONGO USER DOCUMENTATION
Build backend applications for your projects with node-mongo. This is a quick setup, installation, and usage guide. On this page, you will learn how to quickly create a new backend API using node-mongo. Follow hints that give instructions on where to find more robust content on the node-mongo features and commands, or you can just simply check the sidebar.

Install node-mongo CLI
Install CLI globally using this command:
npm install -g @code-collabo/node-mongo-cliCreate a new backend API application
Change directory i.e. cd into any folder of choice on your computer. Then run the node-mongo command together with test-folder and ts as shown in the code block below. This will generate a new backend API called test-folder, and the code in the application generated will be in typescript (ts).
node-mongo test-folder tsRunning the generated backend API application
Change directory i.e. cd into the test-folder application generated earlier. Then follow the steps below depending on the MongoDB connection or setup type that you wish to use.
Step 1
Install dependencies:
npm installStep 2
Ensure you have an internet connection
Have a monogDB atlas cluster set up in the cloud
Get your Atlas mongoDB URI string
Step 3
Rename the
.env.examplefile to.envChange
PORT_ATLASenvironment variable to your preferred port number in the .env fileAdd your Atlas mongoDB URI string to the
MONGODB_ATLAS_URIenvironment variable in the .env file
Step 4
Start the automated development server and choose ATLAS connection:
npm run devStep 4 (alternative)
You can also use the (manual) development server alternative for connection to MongoDB atlas:
npm run dev:atlasStep 1
Install dependencies:
npm installStep 2
Have MongoDB installed and running on your computer
Get your local MongoDB URI string
Step 3
Rename the
.env.examplefile to.envChange
PORT_LOCALenvironment variable to your preferred port number in the .env fileAdd your local MongoDB URI string to the
MONGODB_LOCAL_URIenvironment variable in the .env file
Step 4
Start the automated development server and choose LOCAL connection:
npm run devStep 4 (alternative)
You can also use the (manual) development server alternative for connection to local MongoDB:
npm run dev:localnpm run dev starts the automated development server. It prompts you to choose your preferred connection setup type the first time you use it and saves the chosen connection setup type for every other time you come back to use it. It also automatically installs or sets up the DB and server files for the chosen connection setup type.
npm run dev:restore resets the automated development server back to first-time usage condition i.e. it removes your previously saved connection setup type and the development server will now assume that you are a first-timer. After using this command, you will now have the option to set your preferred connection type again the next time you start the server with the npm run dev command.
npm run dev:change is useful for when you are not a first-time user and want to change your connection setup type without restoring the automated development server to first-time usage condition. It will prompt you to choose your connection setup type, but it will not install the DB and server files for the chosen connection setup type.
API design
A "demo" setup exists in the generated backend API application i.e. demo database collection and schema, /demo endpoints, etc. that you can test with. Find more details about the available test endpoints that you can try out in the table below:
GET /demo
Get all demo items in the database
No Request Body
POST /demo
Create/add new demo item to the database
name, age
GET /demo/:demoId
Get a demo item stored in the database by its ID
No Request Body
PATCH /demo/:demoId
Update the value of one property of an already existing demo item in the database, using the demo item's ID
propName, value
PUT /demo/:id
Update all properties of an existing demo item in the database, using the demo item's ID
name, age
DELETE /demo/:demoId
Delete a demo item from the database, using the demo item's ID
No request body
API call requests and responses
Last updated
Was this helpful?