# Build your own TCP log server with node.js part 1

Date: 2017-05-23

We need to log TCP calls from the ship and give the user option to comment on the fly.

The main problem is that we don&#8217;t have time or resources to put in the server,

I decided to implement a quick and dirty log server with rest API, express, socket.io.

<!--more-->

Install rest server from scratch :

node.js :
```javascript
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm i express -g
sudo npm install -g yo
sudo npm install -g generator-rest</pre>
```

mongoDB:
```shell
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get install -y mongodb</pre>
```

rest server :
```shell
mkdir logserver
cd logserver
yo rest
```


Next -> Next -> Next &#8230;

yo rest:api
```shell
? What's the API name? log
? What's the endpoint name? logs
? Where to put the code? src/api
? Which methods it will have? (Press &lt;space&gt; to select, &lt;a&gt; to toggle all, &lt;i&gt; to inverse selection)C
reate (POST), Retrieve list (GET), Retrieve one (GET), Update (PUT), Delete (DELETE)
? Which methods are protected by the master key? (Press &lt;space&gt; to select, &lt;a&gt; to toggle all, &lt;i&gt; to 
inverse selection)
? Which methods are only accessible by authenticated admin users? (Press &lt;space&gt; to select, &lt;a&gt; to to
ggle all, &lt;i&gt; to inverse selection)
? Which methods are only accessible by authenticated users? (Press &lt;space&gt; to select, &lt;a&gt; to toggle a
ll, &lt;i&gt; to inverse selection)
? Do you want to generate a model? Yes
? Which fields the model will have? (comma separated) source,type,message,comment
 create src/api/log/controller.js
 create src/api/log/index.js
 create src/api/log/index.test.js
 create src/api/log/model.js
 create src/api/log/model.test.js
 conflict src/api/index.js
? Overwrite src/api/index.js? overwrite
 force src/api/index.js
```

run the server for testing :
```npm start```

if you see: Express server listening on http://0.0.0.0:9000, in development mode

then we finish the first part 🙂

now we have a rest server to save the data to the local MongoDB server
