File sharing system made in Node.js with MongoDB, supporting user register, edit and delete, file upload (by selected users) and download and search by multiple standards.
-
Install Node.js, the normal version already comes with NPM
-
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
dataand another one inside it calleddb:
C:\data\db- Add Mongo’s bin folder to the Path Environment Variable (for Windows).
- Create the file
db.jsin the folderconfigwith the following code:
if (process.env.NODE_ENV == "production") {
//URL to your Cloud database
module.exports = { mongoURI: "mongodb+srv://user:password@cluster_name.mongodb.net/database_name?retryWrites=true&w=majority" }
}
else {
//Local URL to access via Browser (27017 is Mongo default connection PORT)
module.exports = { mongoURI: "mongodb://user:password@localhost:27017/database_name" }
}- Start MongoDB, in the Terminal type the following command:
mongod- Create a new database and admin:
mongo
use nameofthedatabase
db.createUser(
{
user: "myDatabaseAdmin",
pwd: "abc123",
roles: [ { role: "dbOwner", db: "nameofthedatabase" } ]
}
)- Create the files
drive_key.jsonandgmail_key.jsonin the folderconfig/googlecontaining the data for authentication with Google APIs, or set it with a.envfile like the following:
# GMail OAuth2 API information
OAUTH_CLIENT_ID_GMAIL = CLIENT_ID
OAUTH_SECRET_GMAIL = SECRET
GMAIL_REFRESH_TOKEN = TOKEN
# Service account
OAUTH_SERVICE_ID_GMAIL = SERVICE_ID
OAUTH_SERVICE_PRIVATE_KEY_GMAIL = -----BEGIN PRIVATE KEY-----\n KEY \n-----END PRIVATE KEY-----\n
# GDrive OAuth2 API information
OAUTH_CLIENT_ID_DRIVE = CLIENT_ID
OAUTH_SECRET_DRIVE = SECRET
DRIVE_REFRESH_TOKEN = TOKEN
# Service account
OAUTH_SERVICE_ID_GMAIL = SERVICE_ID
OAUTH_SERVICE_PRIVATE_KEY_GMAIL = -----BEGIN PRIVATE KEY-----\n KEY \n-----END PRIVATE KEY-----\n- Start the application in another terminal window (
nodemonwill automatically restart your application every time you make a change in any.jsfile and save it, if you don't have the package, you can install it globally on your computer withnpm install -g nodemon):
nodemon app.js- Open
localhost:8081in your Browser and have fun!