E-book web repository made in Node.js with MongoDB, supporting user register/edit, e-book upload/download and search.
-
Install Node.js
-
Install MongoDB
-
Install all dependencies from the package.json file in the current folder, in the Terminal type the following command (you need a package manager):
npm install
- Create a folder in your local drive called
data
and another one inside it calleddb
:
C:\data\db
- Add Mongo’s bin folder to the Path Environment Variable
- Create the file
db.js
in the folderconfig
with the following code:
if (process.env.NODE_ENV == "production") {
module.exports = { mongoURI: "URL_to_your_Mongo_Server" }
}
else {
module.exports = { mongoURI: "mongodb://user:pwd@localhost:27017/nameofthedatabase" } //Local URL to access via Browser
}
- Start MongoDB, in the Terminal type the following command:
mongod
- Create new database and admin:
mongo
use nameofthedatabase
db.createUser(
{
user: "myDatabaseAdmin",
pwd: "abc123",
roles: [ { role: "dbOwner", db: "nameofthedatabase" } ]
}
)
- Start the application (
nodemon
will automatically restart your application every time you make a change in any.js
file and save it, if you don't have the package, you can install it globally withnpm install -g nodemon
):
nodemon app.js
- Open
localhost:8081
in your Browser.