Reputation: 125
I am trying to make login in Node.js. but i am confused how to use database.And my Login.html & database.js is like. http://scotch.io/tutorials/javascript/easy-node-authentication-setup-and-local So please give me proper idea.
<form action="/login" method="post">
<div class="form-group">
<label>Email</label>
<input type="text" class="form-control" name="email">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" name="password">
</div>
<button type="submit" class="btn btn-warning btn-lg">Login</button>
database.js:
module.exports = {
'url' : 'your-database-here'
};
Upvotes: 3
Views: 785
Reputation: 19035
In your server.js
should be this bit of code (assuming you are following the tutorial you linked exactly).
var configDB = require('./config/database.js');
mongoose.connect(configDB.url);
According to that code, your database.js
file must be in a config folder (rather then in the same folder as server.js
). So make sure you are doing that.
Next, place your mongodb url like so in your database.js
.
module.exports = {
'url' : 'mongodb://<user>:<pass>@mongo.onmodulus.net:27017/Mikha4ot'
};
Make sure to replace <user>
with your username and <pass>
with your password.
I will help you.
module.exports
Upvotes: 2
Reputation: 943128
From the tutorial you link to:
Fill this in with your own database. If you don’t have a MongoDB database lying around, I would suggest going to Modulus.io and grabbing one. Once you sign up (and you get a $15 credit for signing up), you can create your database, grab its connection url, and place it in this file.
Otherwise you will need to download MongoDB and run your own instance of it.
Alternatively, rewrite the database code to use a different kind of database and find an NPM module to interface with it.
Upvotes: 0
Reputation: 10081
It depends which database you are using. Different databases often have different ways of accessing them. For example, if you are using postgres you can use node-postgres from npm.
Upvotes: 1