0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Node.jsがわかった気になれるまとめ

0
Last updated at Posted at 2025-12-31

Node.jsがわかった気になれるまとめ

超短時間でNode.jsを軽く理解した方法をまとめました。

開発環境

StackBlitzを使った。
https://stackblitz.com/edit/node-k7fuav8c?file=index.js

🧭 実際にやった3ステップ

1:Hello World(環境確認)

node -v
# => Hello Node.js v20.19.1!

2: 非同期処理を体感

function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function main() {
  console.log('1. start');
  console.log('2. wait 2 sec...');
  await wait(2000);
  console.log('3. done');
}

main();
console.log('★ これはどこで出る?');

結果:
★ が先に出る!

PHP(Laravel)であれば、同期で、終わるまで待つ
Node.jsは非同期で、待ち時間で別の仕事する


3: ExpressでREST API構築

npm install express

index.js

const app = express();

// Route::get('/', ...)
app.get('/', (req, res) => {
  res.send('Hello Express!');
});

// Route::get('/user/{id}', ...)
app.get('/user/:id', (req, res) => {
  res.json({
    id: req.params.id,
    name: "Nakamura",
    role: "Backend Engineer",
    msg: "Laravel経験があれば問題なし!"
  });
});

app.listen(3000, () => {
  console.log('Server started on port 3000');
});

ブラウザで
http://localhost:3000/user/123
→ JSON返ってきたら 学習完了!🎉

Node.js / Express Laravel
npm install composer require
package.json composer.json
app.get('/path', ...) Route::get('/path', ...)
res.json() response()->json()
Middleware Middleware
express.urlencoded() $request->input()
express.json() $request->json()
Controller (手書き) Artisanで自動生成
async / await(非同期) 同期処理(ここが最大の差分!)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?