NodeJs Javascript Server: an open source Javascript server
NodeJs (Node.js) is an open-source, cross-platform, server-side JavaScript runtime environment that runs on a JavaScript Engine (V8 engine) and executes JavaScript code outside a web browser, which was designed to build scalable network applications. NodeJs lets developers use JavaScript to write command line tools and for server-side scripting-running scripts server-side to produce dynamic web page content before the page is sent to the user's web browser. Consequently, NodeJs represents a "JavaScript everywhere" paradigm, unifying web-application development around a single programming language, rather than different languages for server-side and client-side scripts.
Written in: C
, C++
, Javascript
Project Goals
- NodeJs is primarily used for non-blocking, event-driven servers, due to its single-threaded nature
- It's used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind
- It does offer an asynchronous event-driven JavaScript server-side runtime
- NodeJs is well suited for handling concurrent connections, making it an excellent framework to develop real-time as well as multi-user web apps
- It doesn't support multi-threaded programming yet ; it is able to serve way more complicated applications than Ruby, but it's not suitable for performing long-running calculations or heavy load tasks
Project Features
- Asynchronous and Event Driven
- Single Threaded but Highly Scalable
- No Buffering - NodeJs applications never buffer any data ; these applications simply output the data in chunks
- Quick execution of code: Javascript is lighweight and fast
- Cross-platform compatibility: NodeJS may be used on a variety of operating systems, being very portable
Project Design and Security
- Very Fast, built on Google Chrome's V8 JavaScript Engine
- Used for I/O bound Applications, Data Streaming Applications, Data Intensive Real-time Applications, JSON APIs based Applications, Single Page Applications
- Code for large applications may be complex due to the asynchronous nature of NodeJs
- New features are constantly being added to the V8 engine ; generally speaking, expect them to land on a future NodeJs release, although timing is unknown
- NodeJs provides a simple way to list all dependencies and respective versions that ship with a specific binary through the process global object
Sample Configuration
// Once the NodeJs is installed, create a file named `app.js` containing the following code
// it will start a NodeJS sample app (Hello World) on port 8077 at 127.0.0.1
// to run this application type in a terminal: `node app.js` ; open in the browser: http://127.0.0.1:8077
const http = require('http');
const hostname = '127.0.0.1';
const port = 8077;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});