I planned to design a web app that provides apis and web site, this is because the app can be used with mobile.
I'm currently using node-restify to provide the api, but now I need a way to serve dynamic pages of the app.
My initial idea was to use just ExpressJS to provide pages and APIs but I've read node-restify is much faster. Now my problem is that with restify I cannot serve html pages rendered in ejs.
Is there a way to have one app only and integrate express with restify.
Any suggestion?
It's interesting what you've written here, because according to this benchmark (16th March 2012):
http://blog.perfectapi.com/2012/benchmarking-apis-using-perfectapi-vs-express.js-vs-restify.js/
Restify is a lot slower then Express.
Express can easily handle ~1500 requests per second while Restify only ~250 per second.
But even if they already improved Restify I doubt that it can be faster then Express which is already extremely fast. Not to mention that it is entire framework with very useful other tools.
Concluding: use Express.js.
Check this out for api:
https://github.com/rahpal/RestOnNode
RESTful framework on NodeJS
This project is build using the same project archutecture which is followed by ASP.Net WebApi 2.0. That means it will be having controllers, authentication mechanism etc. to start with. All you need to do is create your own controllers.
Related
I have a question already search on google but not find a good answer.
What is the job of nodejs & ExpressJS in mean stack development ? Like is it some thing like php to create api and angular will call it ? Or something else
You're exactly right, Node.js is used in MEAN stack to create backend code and APIs that are called from a frontend Angular app.
Angular is the way to create an SPA (Single Page Application).
Wikipedia:
A single-page application (SPA) is a web application or web site that
interacts with the user by dynamically rewriting the current page
rather than loading entire new pages from a server.
ExpressJS
What is Express.js. Express is a fast, assertive, essential and
moderate web framework of Node.js. You can assume express as a layer
built on the top of the Node.js that helps manage a server and routes.
It provides a robust set of features to develop web and mobile applications.
So on top of node-js which is your server side application where you can build your apis that your angular SPA will consume, you have Express JS which is a ready solution to help you.
This way, you will not need to solve problems like routing which have already been solved by the framework in an "optimal" or at least commonly agreed "good enough" way.
There is an excellent answer on express js in stackoverflow here
Yes, you right it is like so. NodeJs is used to create a server, then APIs and Angular call those API from the Front-End.
Detailed Description:
What is NodeJs
You can create a server using NodeJs where you will have a bunch of APIs.
These APIs can be called from an Angular app.
Official Definition: Node.js is a runtime environment that executes JavaScript code outside of a browser. Outside of a browser means Server.
What is ExpressJs
ExpressJS is a prebuilt NodeJS framework that can help you in creating server-side web applications faster and smarter.
Note: It is not necessary to use ExpressJs if you are using NodeJs.
What is Angular
Angular is a framework for building Single Page Application(SAP) web
applications.
SAP means your site does not reload the page when you move from one page to another.
Your Angular app calls NodeJs API.
Angular is a library for building Single Page Applications which (typically) run inside a web browser.
Node.js is a way of running software written in JavaScript outside of a browser. It has many uses.
Software written to run under Node.js — that is strictly relevant to the topics you are asking about — includes:
Build tools used with Angular (converting code is written in ways optimal for developers to edit and debug to ways optimal for delivering to and running in a browser).
Other helper tools for software development (such as #angular/cli which creates a skeleton set of code for an Angular project)
HTTP servers used to provide web services (a type of API) for client applications (which may be written in Angular) to access
Express.js is a library for Node.js which provides prewritten solutions for many of the tasks an HTTP server needs to perform.
You can write many kinds of software in Node.js. I have some code lurking around that loops over all the images in a directory and spits out a PDF of them. It doesn't even go near the Internet.
I am fairly new to the web development and I am still learning.
I am trying to build a back end for my web application. I am currently using react with redux for my front end. My question is, in order to create a back end do I need to use the react-router or do I have to use a completely different platform like Node.js. Thank you in advance!!
In order to create a backend, you will need to build a server-side application using Node, .NET Core, Java, PHP... and the list goes on. Seems like you're into JS, so Node would likely be your choice. You have a few options, such as embedding your frontend application in views served by your backend, or keeping them separate, like a frontend talking to API endpoints using the Fetch API.
React-router, on the other hand, will allow you to move through the different screens of the single-page app you've created. It won't help you to make API endpoint calls.
So, as you can see, the two things aren't related even though they sound similar. In short, use react-router to navigate around your app, and use the Fetch API (or a component like Axios that has better compatibility for older browsers) to make your API endpoint requests.
I want to build a self-hosted website with nodejs and the express framework because I'm already familar with that. However, using a CMS for this project is a requirement, so I'm looking for a suited and easy-to-use/-learn CMS and discovered strapi which I quite like.
Setting up an API with strapi is easy indeed but now I'm struggling with adding strapi to an express server. My goal is one express server with strapi, which also hosts the website. So, I can control the routing with express (which I'm used to) and can render the site on the server.
Can somebody explain me how to do that and maybe give a small example? The examples I found, are only about hosting the API externally and using a client-side web framework or a static site generator.
Or is my vision not possible with strapi and I should use another CMS like KeystoneJS (which is already built on Express)?
Thanks in advance!
Using Express with Strapi must be very complex and does not really make sense.
Strapi is based on Koa, which has been designed by the team behind Express. If you are coming from Express, eyou will get confortable with Koa very quickly. Here is the documentation: https://koajs.com.
I have been searching all over for a tutorial that could make a RESTFul API without using any frontend javascript to no avail. I am very new to Javascript/ web-development and have been doing many tutorials and mini projects to get myself acquainted with it.
This is a test for a job at a startup as they looking for an entry level developer. Their requirements are much different as they want me to use their in house build APIs.
What I am looking for is some help on how to get started building a RESTful API using node.js, express, Mongo and without using any frontend javascript. Thanks.
Recommendations for tutorials usually don't make good questions for Stack Overflow, but you might want to take a look at the following books. They helped me out quite a bit when getting started with Node:
Express Web Application Development
Advanced Express Web Application Development
RESTful Web API Design with Node.js
As others have commented, a REpresentational State Transfer API is implemented server-side. You could consume such an API from the client-side using JavaScript, but not build one on the client-side.
Express is a very popular web framework for Node, and you can certainly use it to build APIs, but you might also take a look at Restify. Hope that helps you out.
I am a newcomer to node.js techique stack. I found some many articles are introducing node.js and Express. I know Express is a good web framework including template engine, routing, etc. It is popular and active framework. There are some point I am confused:
Why there are still so many web frameworks are built on Express? Is it lack of much features?
Why does Express do not evolve to add more features? Is it a lower-level web framework?
What are the product orientation for Express and others (which is built based on Express)?
Express is designed to only do a few things well. It will take care of routing and some templating for you, but it isn't a complete MVC solution. Since express takes care of a lot of basic middleware required for MVC frameworks, these frameworks are built on express.