ℹ️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.
Operating System Requirements: Works on Mac, Windows, and Linux Operating Systems.
Installation Requirements: To be able to use node-mongo, you need Node js to be installed on your computer. You can get Node js from the official Node js website, or install Node js through the Node Version Manager (NVM).
Supported Node.js versions: Node js versions 16.x - 20.x
Install node-mongo CLI
Install CLI globally using this command:
Create 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).
See Reference Guide: node-mongo features and commands for more details on other types of templates you can generate apart from the typescript (ts) template. You can find this in the sidebar.
Running 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:
Step 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.example
file to.env
Change
PORT_ATLAS
environment variable to your preferred port number in the .env fileAdd your Atlas mongoDB URI string to the
MONGODB_ATLAS_URI
environment variable in the .env file
Step 4
Start the automated development server and choose ATLAS connection:
Step 4 (alternative)
You can also use the (manual) development server alternative for connection to MongoDB atlas:
npm 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:
Help needed (content not available yet): Contribute to this doc. Help users know how they can add their own db collections, schemas, endpoints, files, etc. to the generated backend API application.
API call requests and responses
Help needed (content not available yet): Contribute to this doc and node-mongo API. Help create swagger documentation for testing API call requests and responses, and help link to this doc. Instead of what we have here now.
Last updated