« Back to Search  |  Reader Mode  |  Switch to Full Retro Site View Links: Stay in Reader  |  Retro Mode: ON  |  Original »
nodejs.org · Extracted in 452 ms

Node.js -- Run JavaScript Everywhere

Source: https://nodejs.org/en

Run JavaScript Everywhere

Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.

Get Node.js® Get Node.js® Get security support
for EOL Node.js versions
Cloudflare HeroDevs DigitalOcean MacStadium TuxCare Vercel Microsoft Azure NodeSource Node.js is proudly supported by the partners above and more .
// server.mjs

import {  } from 'node:http';

const  = ((, ) => {

  .(200, { 'Content-Type': 'text/plain' });

  .('Hello World!\n');

});

// starts a simple http server locally on port 3000

.(3000, '127.0.0.1', () => {

  .('Listening on 127.0.0.1:3000');

});

// run with `node server.mjs`
JavaScript
// tests.mjs

import  from 'node:assert';

import  from 'node:test';

('that 1 is equal 1', () => {

  .(1, 1);

});

('that throws as 1 is not equal 2', () => {

  // throws an exception because 1 != 2

  .(1, 2);

});

// run with `node tests.mjs`
JavaScript
// crypto.mjs

import {  } from 'node:crypto';

import {  } from 'node:fs/promises';

const  = ('sha1');

.('hex');

// ensure you have a `package.json` file for this test!

.(await ('package.json'));

.();

const  = .();

// run with `node crypto.mjs`
JavaScript
// streams.mjs

import { ,  } from 'node:fs';

import {  } from 'node:stream/promises';

import {  } from 'node:zlib';

// ensure you have a `package.json` file for this test!

await (

  ('package.json'),

  (),

  ('package.json.gz')

);

// run with `node streams.mjs`
JavaScript
// threads.mjs

import { , ,

  ,  } from 'node:worker_threads';

if () {

  const  = 'some data';

  const  = new (import.meta., { :  });

  .('message',  => .('Reply from Thread:', ));

} else {

  const  = ;

  .((.toUpperCase()));

}

// run with `node threads.mjs`
JavaScript

Learn more what Node.js is able to offer with our Learning materials .