Create a new MEAN project
If you would like to create a new MEAN project, follow the steps below:
Log in to your server console.
Create a new folder for your project.
$ mkdir installdir/projects
Create a new Express project:
$ cd installdir/projects $ express --view pug sample
The MEAN stack already has the required components installed in Node.js, but if you prefer, you can install them in the new project folder:
$ cd installdir/projects/sample $ npm install
Start the application.
$ DEBUG=sample:* ./bin/www
This will start the Express server for your application on port 3000.
To access the application and see its output, browse to http://localhost:3000/. To end the application, terminate the running Express process. Learn more about how to access the application.
You can now proceed to enhance your project by connecting it with MongoDB or by adding AngularJS.
Connecting to MongoDB
You can connect your application with MongoDB using MongooseJS, an object modelling driver for Node.js. It is already installed in the MEAN stack so you only have to add the following lines to your app.js file:
var Mongoose = require('mongoose'); var db = Mongoose.createConnection('mongodb://USER:PASSWORD@localhost/DATABASE');
Note that the socket name depends on the MongoDB port in use.
You can use install AngularJS in your application with Bower. Create a file named .bowerrc in your application with the following content:
Then, run this command in the project directory:
$ bower install angular