Quote:
If I've understand correctly I need to use Express to serve the client side of my project (display the results on a webpage). Is this the right way to use NodeJS with an API or are there other ways?
Oh, no no no, you are all wrong. Express is a server wrapper for Node.js, and provides you with the server-side programming services and functionality. In your own code, please check,
server.get('/', function(req, res) {
res.render('index', {title: 'Twitter', data: theTweets});
});
The client-side library in your code might be
hogan-express[
^] and that will be responsible for generating dynamic HTML content and providing it. Still, we have not yet reached the client-side. The ruler of the client-side realm is JavaScript. I do not see any JavaScript library that you are injecting there.
But if you meant, to
serve the requests: Then yes, you are right, Express is used to serve the requests in Node.js as it provides a flexible way to manage your server. :-)
Quote:
Is this the right way to use NodeJS with an API or are there other ways?
Yes, Express is a great library to serve most of the purposes that you have in mind. Now understand this, that you are only calling the API to get some result. In Node.js the preferred result from an API is the JSON document, since Node.js has native support for that.
The Twit library would definitely have its own documentation that you can reach and understand to further proceed.
Quote:
In my application, I'm using hogan-express as template engine, do I need to use a template engine or can I use just normal html?
You are a bit wrong in this part too, sorry. hogan-express has been long deprecated by its own manager, developer. Check the link I attached for hogan-express. I can recommend using either Pug, or EJX, there are many other template libraries, but these are somewhat bearable. :D
Lastly, simple HTML files will not serve you any benefit, since you will need to use a template nonetheless to show the tweets on the page, otherwise, a static page won't contain much information — unless you plan to create a new HTML page for each request.
Twit package on NPM[
^]
You might be interested in my Node.js sample, that I created for beginners to try and learn, it demonstrates basics of Node.js, Express, Pug and a few more technologies that you can find on the repository:
GitHub - afzaal-ahmad-zeeshan/nodejs-dockerized: Dockerized Node.js application.[
^]