Member-only story
In this tutorial I will show you how to set up both a Node.js server and an iOS app that interacts with it.
Node.js
We will start by setting up the server. This section is based on the Android version of this tutorial.
Download and install Node.js.
Create a directory for your server app. Let’s call it node_server
.
mkdir node_server
cd node_server
Setup a new project with the Node Package Manager:
npm init
Accept the defaults except for the entry point. I will use the name app.js
instead of index.js
. Then create a file called app.js
.
touch app.js
Open that file in your favorite editor. Many people use Visual Studio Code.
Let’s use the code from the getting started guide. Paste it into your app.js file.
const http = require('http');const hostname = '127.0.0.1';
const port = 3000;const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});server.listen(port, hostname, () => {
console.log(`Server running at…