3

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' 

};

3 Answers 3

2

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.

Need help getting a mongoDB database for yourself?

I will help you.

1:

Go to Mongolab's signup page.

2:

Once signed up, tap the button.

3:

Choose the Cloud provider you want. (I just kept Amazon since it was already selected)

4:

When you get to the Plan section, make sure you choose the free plan (unless of course you want to pay).

5:

Once you create the database, click into it!

6:

Now you will find the connection url that you want to put in your module.exports

Sign up to request clarification or add additional context in comments.

2 Comments

If i used mySql Database then how i can used?
Try submitting a new question about that. Something like "How do I connect to a mySQL database with Node.js?". You should try searching on Google first, of course. Try including site:stackoverflow.com or site:github.com with some keywords for better results.
1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.