Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add information about npm scripts #19

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions Node.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ Download and run the installer for your system from [http://nodejs.org/download/

You now have `node` and `npm` installed in your `$PATH`.


## Using `node`
`node` is the program interpreter. You can run a javascript program:

```
```console
$ node program.js
```

You can also start node in interactive ([REPL](http://nodejs.org/api/repl.html)) mode:
```
```console
$ node
```


## Using `npm`
`npm` is used to install modules and to publish your own. It is reasonably well documented at the [npm website](https://www.npmjs.org/doc/cli/npm.html).

In brief, you can find modules to use at [npm.im](https://npm.im) with the search feature. Then, you can install them:

```
```console
$ npm install foo
```

Expand All @@ -34,15 +36,45 @@ When you first clone a project using node, you need to run `npm install` which w

## Running node programs
Typically this is done via
```console
$ npm start
```
$ npm run

When you first clone a repository, make sure to run `$ npm install` in the directory to download all of the dependencies.

When creating a node program, you can set the start script by added it to your `package.json` like this:
```js
{
"scripts": {
"start": "node index.js"
}
}
```


## Testing node programs
Typically this is done via
```
```console
$ npm test
```

When you first clone a repository, make sure to run `$ npm install` in the directory to download all of the dependencies.

When creating a node program, you can set the test script by added it to your `package.json` like this:
```js
{
"scripts": {
"test": "node test.js"
}
}
```


## Scripting tasks (builds, testing, etc)
In addition to `start` and `test` scripts mentioned above, npm includes a way to run other tasks related to your program by
adding them to the `scripts` property in `package.json`. This is a powerful and standard way to add functionality to node
programs. Read [this excellent blog post](http://substack.net/task_automation_with_npm_run) to learn more about this.


## `package.json` & configuration
`package.json` has lots of fun stuff for your project. All of the fields are optional. A great resource for exploring what fields are available is [package.json.nodejitsu.com/](http://package.json.nodejitsu.com/)