package.json
We're going to create a package.json
file for our new application. This contains information about your app, such as:
touch app.js
npm init
You'll be prompted through a variety of questions, such as:
name: an_api
version: (1.0.0) 0.1.0
description: My first express api
entry point: (index.js) app.js
test command:
git repository: https://github.com/code-for-coffee/express_api
keywords:
author: your-user-name
license: (ISC) MIT
This generates the following package.json
file:
{
"name": "Tasker",
"version": "0.1.0",
"description": "The MEAN way to track your Tasks!",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/code-for-coffee/Tasker"
},
"author": "code-for-coffee",
"license": "MIT",
"bugs": {
"url": "https://github.com/code-for-coffee/Tasker/issues"
},
"homepage": "https://github.com/code-for-coffee/Tasker"
}
Use npm install <pkg> --save
afterwards to install a package and save it as a dependency in the package.json file.
We're going to be using the following dependancies in our MEAN application:
To get started, let's go ahead and add Express.js to our project by running the following command:
npm install express --save
package.json
. Go ahead - take a look!"dependencies": {
"express": "^4.12.4"
}
node_modules
.package.json
file from another project, you can run the npm install
command to fetch/install the required packages for that app!We want to be able to generate applications in the same way that Ruby on Rails can. We're going to run a command to install an Express.js application generator:
sudo npm install -g express-generator
We'll touch more on this later.
We're going to run a few commands to make sure we have the required dependencies for our application:
node --version #checks node version
npm --version #checks npm version
express --version #checks express version