First web application with Node.js

very easy. With only few lines you can launch a web application. First, create a new folder and make a following file, package.js.

package.js
--
{
    "name": "node-api",
    "main": "server.js",
    "dependencies": {
        "express": "~4.0.0"
    }
}
--

in the same folder, run in a terminal or command prompt:

npm install 

the, create a file, server.js

server.js
-- 
var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})
--
 
then, run following line in a terminal
 
node server.js
 
browse http://localhost:8080 to see 'hooray! welcome to our page!'

This should be the first your web page created with Node.js. To create your API, visit the following helpfull page:
https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4

コメント

人気の投稿