Node.js is an exciting new development framework. Here's a quick overview of how to get Node working on MAC OSX with npm, the package manager for node.

Install Homebrew (see article for details..)

#download node
brew install node
#check version node
node -v

Installing npm

npm is Node's package manager:It is now installed automatically with Node.js ( no need to do a separate installation).

launch Node

# 1)create simple hello world
touch [path]/server.js

# 2)write in file [path]/server.js
var util = require('util'),    
http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type':    'text/plain'});
res.write('hello, nodejs \n')

#3 send request on server
curl localhost:8000
>hello, nodejs

Running in the background

running server script with the 'node' command the server will start as a long running process ( block the current shell until it crashes or is forced to exit with Ctrl-C).

$ nohup [path]/server.js > output.log &

Running forever....

The purpose of Forever is to keep a child process running continuously and automatically restart it.

npm install forever

 start          start SCRIPT as a daemon
 stop           stop the daemon SCRIPT
 stopall        stop all running forever
 list           list all running forever scripts

 #start example forever
 forever start [path]/server.js

© 2021. All Rights Reserved.

Ghostium Theme by @oswaldoacauan

published with Ghost

Privacy Policy