Build web application
Create the client app
- Create new directory.
mkdir my_webapp
cd my_webapp
- Then we can initialize the Node.js project.
Create Express app
- Install Express.
- After running this command, we will see the dependency appear in the package.json file. Additionally, the node_modules directory and package-lock.json files are created.

- Create new file name app.js.
- Select file app.js and paste this code. Then save it.
var express = require('express');
var app = express();
var fs = require('fs');
var port = 8080;
app.listen(port, function() {
console.log('Server running at http://127.0.0.1:', port);
});

Create a REST API
- Add the following code in the
app.js
file.
var express = require('express');
var app = express();
var fs = require('fs');
var port = 8080;
/*global html*/
// New code
app.get('/test', function (req, res) {
res.send('the REST endpoint test run!');
});
app.get('/', function (req, res) {
html = fs.readFileSync('index.html');
res.writeHead(200);
res.write(html);
res.end();
});
app.listen(port, function() {
console.log('Server running at http://127.0.0.1:%s', port);
});
Create HTML content
- Create file name index.html.
- Select file index.html. Then paste the code below and save.
<html>
<head>
<title>Elastic Beanstalk App</title>
</head>
<body>
<h1>Welcome to the FCJ Workshop</h1>
<a href="/test">Call the test API</a>
</body>
</html>

Running the code locally
- Select file package.json.
- Update package.json with script and save.
"scripts": {
"start": "node app.js"
},

- In terminal, run command.
- Go to the link that appear to see the result.
