相关文章推荐
14
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

nodejsのpathモジュールの使い方

Last updated at Posted at 2020-03-07

pathモジュールの使い方をまとめました。

  • npmがインストールされていること
  • touch コマンドでファイルを作成します。

    $ touch test.js
    
    test.js
    const path = require('path')
    console.log('basename:', path.basename('./dir/test.txt'))
    console.log('dirname:', path.dirname('./dir/test.txt'))
    console.log('extname:', path.extname('./dir/test.txt'))
    console.log('parse:', path.parse('./dir/test.txt'))
    console.log('join:', path.join('dir', 'dir2', 'test.txt'))
    console.log('relative:', path.relative('./dir', './dir2/test.txt'))
    

    nodeコマンドを実行します。

    $ node test
    
    basename: test.txt
    dirname: ./dir
    extname: .txt
    parse: { root: '',
      dir: './dir',
      base: 'test.txt',
      ext: '.txt',
      name: 'test' }
    join: dir/dir2/test.txt
    relative: ../dir2/test.txt
    

    この記事は以下の情報を参考にして執筆しました。

  • パス操作(path)とファイル操作(fs)
  • 14
    8
    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
    14
    8

    Delete article

    Deleted articles cannot be recovered.

    Draft of this article would be also deleted.

    Are you sure you want to delete this article?

     
    推荐文章