0

I visited the official io.js site (https://iojs.org/) and installed the 1.0.1 release, Mac version. After I installed this, I went to my terminal window and typed:

iojs app.js

Which I presume is the way to create a io.js project? I'm trying to create a io.js project using Express. Any help? Thank you.

pourmesomecode
  • 4,108
  • 10
  • 46
  • 87

2 Answers2

2

If iojs is a replacement for Node, then manually create a new file called app.js and put this in it:

var http = require('http');

http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World\n');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

And then run it with iojs app.js.

It says it's npm compatible, so you create a new package.json file via npm init if you desire.

mpen
  • 272,448
  • 266
  • 850
  • 1,236
1

Irrespective of using NodeJS or io.js, the answer should be the same. You're going to start an express application and start it.

Assuming you've installed io.js already, on the command line type:

#install a generator for the express
npm install express-generator -g 
application

mkdir my-application-folder
cd my-application-folder

#use the express generator to generate a new application
express  

#now install node_modules from package.json
npm install

and once you've got the files, you can start the application with:

npm start

So this should start the application, irrespective of it being nodeJS or iojs.

However, if you're starting out with Node/io and you're looking to make this your webserver, be aware there are a number of add-ons and setting tweaks which are required before an application is suitable for production. See here and here, for example

David
  • 964
  • 7
  • 14